AngularJS ng-readonly 指令
定義和用法
ng-readonly
指令設置表單字段(input 或 textarea)的 readonly
屬性。
如果 ng-readonly
屬性中的表達式返回 true
,則表單字段將為只讀。
ng-readonly
指令對于在 true 和 false 之間切換值是必要的。在 HTML 中,你不能將 readonly 屬性設置為 false(readonly 屬性的存在會使元素變為只讀,無論其值如何)。
實例
使輸入字段只讀:
只讀:<input type="checkbox" ng-model="all"> <br> <input type="text" ng-readonly="all">
語法
<input ng-readonly="expression"></input>
受 <input>
, <textarea>
元素支持。
參數
參數 | 描述 |
---|---|
expression | 如果返回 true,將設置元素的 readonly 屬性的表達式。 |