如何在angularjs中使用ng-disabled和div?

时间:2021-08-22 19:43:41

ng-disabled="condition" not disabling the div even when the condition is true.

ng-disabled =“condition”即使条件为真也不禁用div。


<div ng-disabled="true">
// display something
</div>

2 个解决方案

#1


3  

you can try

你可以试试

<fieldset ng-disabled="true">
// display something
</fieldset>

#2


2  

Note: You can use ng-show / ng-hide directive for DIV elements to show or hide !

注意:您可以使用ng-show / ng-hide指令显示或隐藏DIV元素!

Use for Form Elements for appropriate usage of ng-disabled directive. see below code snippet.

用于表单元素以适当使用ng-disabled指令。见下面的代码片段。

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="">
 <label>Click me to toggle: <input type="checkbox" ng-model="checked"></label><br/>
 <button ng-model="button" ng-disabled="checked">Button</button>
</div>

Reference: https://docs.angularjs.org/api/ng/directive/ngDisabled
What to disable: https://www.w3.org/TR/html5/disabled-elements.html

参考:https://docs.angularjs.org/api/ng/directive/ngDisabled禁用内容:https://www.w3.org/TR/html5/disabled-elements.html

Below elements can be disabled.

可以禁用以下元素。

  1. button
  2. 按键
  3. input
  4. 输入
  5. select
  6. 选择
  7. textarea
  8. textarea的
  9. optgroup
  10. OPTGROUP
  11. option
  12. 选项
  13. fieldset
  14. 字段集

#1


3  

you can try

你可以试试

<fieldset ng-disabled="true">
// display something
</fieldset>

#2


2  

Note: You can use ng-show / ng-hide directive for DIV elements to show or hide !

注意:您可以使用ng-show / ng-hide指令显示或隐藏DIV元素!

Use for Form Elements for appropriate usage of ng-disabled directive. see below code snippet.

用于表单元素以适当使用ng-disabled指令。见下面的代码片段。

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="">
 <label>Click me to toggle: <input type="checkbox" ng-model="checked"></label><br/>
 <button ng-model="button" ng-disabled="checked">Button</button>
</div>

Reference: https://docs.angularjs.org/api/ng/directive/ngDisabled
What to disable: https://www.w3.org/TR/html5/disabled-elements.html

参考:https://docs.angularjs.org/api/ng/directive/ngDisabled禁用内容:https://www.w3.org/TR/html5/disabled-elements.html

Below elements can be disabled.

可以禁用以下元素。

  1. button
  2. 按键
  3. input
  4. 输入
  5. select
  6. 选择
  7. textarea
  8. textarea的
  9. optgroup
  10. OPTGROUP
  11. option
  12. 选项
  13. fieldset
  14. 字段集