AngularJS ng-readonly 指令
示例
使输入字段只读
只读:<input type="checkbox" ng-model="all">
<br>
<input type="text" ng-readonly="all">
自己动手试一试 »
定义和用法
ng-readonly 指令用于设置表单字段(input 或 textarea)的 readonly 属性。
如果 ng-readonly 属性内的表达式返回 true,则表单字段将变为只读。
ng-readonly 指令对于能够将值在 true 和 false 之间切换是必需的。在 HTML 中,你不能将 readonly 属性设置为 false(readonly 属性的存在使得元素只读,而不管其值是什么)。
语法
<input ng-readonly="expression"></input>
支持 <input> 和 <textarea> 元素。
参数值
| 值 | 描述 |
|---|---|
| expression | 一个将在元素返回 true 时设置该元素 readonly 属性的表达式。 |