问题描述
- 请前辈们给这个方法几句话让这个全选的方法不选择disabled的选择框
-
bindCheckAll: function(str) {
var a = document.getElementsByName(str);
var n = a.length;
for (var i = 0; i < n; i++)
a[i].checked = window.event.srcElement.checked;
},
解决方案
a[i].checked = window.event.srcElement.checked;
->
if (!a[i].disabled=='disabled') a[i].checked = window.event.srcElement.checked;
解决方案二:
试试这个
bindCheckAll: function(str) {
var a = document.getElementsByName(str);
var n = a.length;
for (var i = 0; i < n; i++)
if(!a[i].hasAttribute('disabled')){
a[i].checked = window.event.srcElement.checked;
}
},
解决方案三:
这样更简约
bindCheckAll: function(str) {
var a = document.getElementsByName(str);
var n = a.length;
for (var i = 0; i < n; i++)
if(a[i].disabled){
a[i].checked = window.event.srcElement.checked;
}
};
时间: 2025-01-29 21:23:14