HTML 按钮(button)的 disable 属性和 disable property
SAP 電商云 Spartacus UI shipping method radio input 的運行時設(shè)計:
在 div 里通過 ngFor 進行循環(huán)展開。
生成的原生 html 代碼:
關(guān)于 radio input 的測試頁面:
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_radio
在原生 HTML 開發(fā)里,我們可以通過給 input 添加 disabled property,來禁掉它。
在 Angular 開發(fā)里,即使我們使用下面的代碼,也不能工作:
// 注意:這個語法是 disabled property [disabled]="true"應(yīng)該使用 disabled attribute,而不是 disabled property.
根據(jù)這個 StackOverflow 的討論,看下面的代碼:
<input type="radio" name="enabled" [attr.disabled]="null" />Enabled1 <input type="radio" name="enabled" [attr.disabled]="null" />Enabled2<input type="radio" name="disabled" [attr.disabled]="false" />Disabled1 <input type="radio" name="disabled" [attr.disabled]="false" />Disabled2第一組 input 是 enabled 狀態(tài),因為 disabled 屬性為 null. 如果該屬性變?yōu)槿魏纹渌?#xff0c;哪怕是字符串 “false”,也會被當(dāng)成 true 對待,因此第二組會被 disabled.
指導(dǎo)方針:pass null to [attr.disabled] and any non-null value to disable it.
一些測試:
嘗試一下我 buddy Michal 提到的 property binding:
最后的效果:兩個都具有了 disabled 屬性:
更多Jerry的原創(chuàng)文章,盡在:“汪子熙”:
總結(jié)
以上是生活随笔為你收集整理的HTML 按钮(button)的 disable 属性和 disable property的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SAP 电商云 Spartacus UI
- 下一篇: 关于某些 Visual Studio C