AngularJS ng-disabled 指令

定義和用法

ng-disabled 指令設置表單字段(input、select 或 textarea)的 disabled 屬性。

如果 ng-disabled 屬性中的表達式返回 true,則表單字段將被禁用。

ng-disabled 指令對于能夠在 true 和 false 之間切換值是必要的。在 HTML 中,您不能將 disabled 屬性設置為 false(disabled 屬性的存在會使元素禁用,無論其值如何)。

實例

禁用/啟用輸入字段:

禁用表單字段:<input type="checkbox" ng-model="all">
<br>
<input type="text" ng-disabled="all">
<input type="radio" ng-disabled="all">
<select ng-disabled="all">
<option>女性</option>
<option>男性</option>
</select>

親自試一試

語法

<input ng-disabled="expression"></input>

<input><select><textarea> 元素支持。

參數

參數 描述
expression 如果返回 true,則將設置元素的 disabled 屬性的表達式。