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 属性的表达式。 |