gpt4 book ai didi

angularjs - ng-disabled 可以禁用子元素组吗?

转载 作者:行者123 更新时间:2023-12-04 15:44:07 26 4
gpt4 key购买 nike

我正在尝试在其父元素中使用 ng-disabled 禁用一组元素。似乎不起作用。
这是否意味着我必须在所有子元素中使用相同的条件来禁用?

我无法通过将 ng-disabled="true"与 ul 或 li 元素一起禁用来禁用所有元素。它仅在我放入输入元素时才有效。这是它的工作原理吗?此外 ng-disabled="true"不适用于 label 或 span !

<ul style="list-style:none">
<li>
<input type="radio" id="radio1" ng-model="color" value="red">
<label for="radio1" class=""><span>Red</span></label>
</li>
<li>
<input type="radio" id="radio2" ng-model="color" value="green">
<label for="radio2" class=""><span>Green</span></label>
</li>
<li>
<input type="radio" id="radio3" ng-model="color" value="blue">
<label for="radio3" class=""><span>Blue</span></label>
</li>

fiddle : http://jsfiddle.net/chiranjib_halder1/pqvz9veu/3/

最佳答案

您可以使用此指令:
https://github.com/pleerock/angular-disable-all.git
基本上选择指令中的元素并禁用它们。

这是使用此指令的 fiddle 代码:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<script src="https://cdn.rawgit.com/pleerock/angular-disable-all/master/dist/angular-disable-all.min.js"></script>
<body ng-app="radioExample">
<script>
angular.module('radioExample', ['disableAll'])
.controller('ExampleController', ['$scope', function($scope) {
$scope.color = 'blue';
$scope.specialValue = {
"id": "12345",
"value": "green"
};
}]);
</script>
<div ng-controller="ExampleController">
<input type="checkbox" ng-model="isDisabled">Disable all<br>
<ul style="list-style:none" disable-all="isDisabled">
<li>
<input type="radio" id="radio1" ng-model="color" value="red">
<label for="radio1" class=""><span>Red</span></label>
</li>
<li>
<input type="radio" id="radio2" ng-model="color" value="green">
<label for="radio2" class=""><span>Green</span></label>
</li>
<li>
<input type="radio" id="radio3" ng-model="color" value="blue">
<label for="radio3" class=""><span>Blue</span></label>
</li>
<tt>color = {{color | json}}</tt><br/>
<button type="button">Click Me!</button>
</ul>

</div>
</body>

关于angularjs - ng-disabled 可以禁用子元素组吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25344164/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com