AngularJS ng-readonly 指令
实例
将输入字段设置为只读:
<!DOCTYPE html><html><script src="https://cdn.bootcdn.net/ajax/libs/angular.js/1.8.2/angular.min.js"></script><body ng-app="">单击此处将输入字段设置为只读:<input type="checkbox" ng-model="all"><br><br><input type="text" ng-readonly="all"></body></html>
定义与用法
ng-readonly 指令设置表单字段(输入或文本区域)的只读属性。
如果 ng-readonly 属性中的表达式返回 true,则表单字段将为只读。
ng-readonly 指令必须能够在 true 和 false 之间切换。在 HTML 中,不能将 readonly 属性设置为 false(存在 readnonly 的元素就是只读了)。
语法
<input ng-readonly="expression"></input>
由 <input> <textarea> 元素支持。
参数值
| 值 | 描述 |
|---|---|
| expression | 一个表达式,如果返回 true,它将设置元素的 readonly 属性 |