0
我需要遍历所有复选框来设置按钮禁用或不。如果其中一个复选框被选中,则该按钮被启用。然而,它看起来像我的代码没有循环通过复选框。每个函数内的警报不shown.I发现 How to loop through group of check boxes that have same class name?通过在jquery中的classname循环复选框
的循环方法,还有就是我的代码:
function setButton() {
alert('line 24');
var blnDisable = true;
//https://stackoverflow.com/questions/35506843/how-to-loop-through-group-of-check-boxes-that-have-same-class-name
$('.chkItem').each(function (index, obj) {
if (obj.checked == true) {
alert('line 30');
blnDisable = false;
}
});
alert('disable=' + blnDisable);
$("#btnDownload").attr("disabled", blnDisable);
}
'obj'将是一个jQuery对象 - jQuery的对象没有一个'checked'属性 - 使用'this'的实例 - '如果(this.checked)' – tymeJV
@tymeJV Im相当河畔' obj'将是一个HTML元素。 @op什么时候setButton被调用? –
或内置的jquery“prop”函数:'if(obj.prop(“checked”))' – MacPrawn