jquery复选框问题 - 不检查它是否禁用 [英] jquery checkbox issue - do not check if it's disabled
本文介绍了jquery复选框问题 - 不检查它是否禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每行有5个复选框。第一个是全部。我试图看看其他人是否被禁用。因此,如果有人点击ALL复选框,我需要确保禁用的选项未被选中。这是我有:
I have 5 checkboxes in each row. The first one is 'ALL'. I am trying to see if any of the others are disabled. So, if somebody clicks on 'ALL' checkbox, I need to make sure the disabled ones are not checked. This is what I have:
("input[name^=all_]").each(function() {
var input = $(this);
var name = input.attr('name');
var num = /\d+$/.exec(name)[0];
$(this).click(function() {
if ($('"#G"+num').attr('disabled',false)) {
$("#G"+num).attr('checked', $("#all_"+num).is(':checked'));
}
if ($('"#E"+num').attr('disabled',false)) {
$("#E"+num).attr('checked', $("#all_"+num).is(':checked'));
}
if ($('"#W"+num').attr('disabled',false)) {
$("#W"+num).attr('checked', $("#all_"+num).is(':checked'));
}
if ($('"#S"+num').attr('disabled',false)) {
$("#S"+num).attr('checked', $("#all_"+num).is(':checked'));
}
});
});
事实是,一旦点击ALL,残疾人仍然会被检查。我做错了什么?
The thing is, the disabled ones still gets checked once I click on 'ALL'. what am i doing wrong? thanks in advance.
推荐答案
此工作原理:
if ( !$("#G"+num).is(':disabled') ) {
$("#G"+num).attr('checked', $("#all_"+num).is(':checked'));
}
if ( !$("#E"+num).is(':disabled')) {
$("#E"+num).attr('checked', $("#all_"+num).is(':checked'));
}
if ( !$("#W"+num).is(':disabled') ) {
$("#W"+num).attr('checked', $("#all_"+num).is(':checked'));
}
if (!$("#S"+num).is(':disabled')) {
$("#S"+num).attr('checked', $("#all_"+num).is(':checked'));
}
});
这篇关于jquery复选框问题 - 不检查它是否禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文