我正在编写 Web 基础项目,并且正在使用 angularjs。我在 select html 元素上发现了 ng:disabled 指令的小错误。如果该元素被禁用,我仍然可以使用键盘向下和向上箭头更改其值。
所以我想实现的是禁用select元素并消除这个小东西。
有人能解释一下这个指令是如何工作的吗??我看过angularjs,但无法弄清楚。
这是错误还是正常行为,我无法理解某些东西?
感谢您提前回答。
例子:
http://jsfiddle.net/kickwce/m23Gr/1/
<select class="select input-large" id="listType" name="listType"
ng-model="listType" ng-disabled="listType">
<option value="">- choose -</option>
<option value="item1">List of tracks</option>
<option value="item2">List of collections</option>
</select>
最佳答案
问题似乎是选择框没有失去焦点。一个指令可以解决这个问题:
myApp.directive('blur', function () {
return function (scope, element, attrs) {
attrs.$observe('blur', function (newValue) {
newValue != "" && element[0].blur();
});
}
});
HTML:
<select ... ng-model="listType" ng-disabled="listType" blur="{{listType}}">
Fiddle 。
您可能应该在选择列表中使用 ng-options。
关于javascript - ng :disabled does not work with select html element,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14288436/