我在一个表中有多个复选框,我已经编写了用于选择/取消选择所有复选框并使用它启用/禁用按钮的代码。(全选复选框是列的标题)
$(function(){
$('#SelectAll').click(function(event) {
if(this.checked) {
// Iterate each checkbox
$(':checkbox').each(function() {
this.checked = true;
});
$('#Assign').removeAttr("disabled");
}
if(!this.checked) {
// Iterate each checkbox
$(':checkbox').each(function() {
this.checked = false;
});
$('#Assign').attr("disabled","disabled");
}
});
});
尽管如果用户决定单独检查复选框并在他的过程中取消选中所有复选框,我该如何编写下面的代码来检查它们是否都未选中并禁用按钮
$(function(){
$(':checkbox').click(function(event){
if(this.checked){
$('#Assign').removeAttr("disabled");
}
if(!this.checked){
//Need to put code here to check if all of them are unchecked
{
//disable the Assign button if all are unchecked by user
$('#Assign').attr("disabled","disabled");
}
}
});
});