2013-02-15 82 views
0

我正在使用以下Jquery来检查/取消选中复选框,但其中的某些框已禁用,因此我无需进行检查。选中/取消选中勾选复选框,但忽略任何禁用选项

有没有办法让脚本忽略禁用的复选框?

$('.uncheck').click(function() { 
    if ($(this).is(':checked')) { 
     $('.customers input:checkbox').removeAttr('checked'); 
    } else { 
     $('.customers input:checkbox').attr('checked', 'checked'); 
    } 
}); 
+1

但是,你需要禁用取消复选框? – 2013-02-15 10:11:13

+0

马蒂亚斯残疾人复选框将不会首先被检查。我现在整理它。 – flyersun 2013-02-15 10:13:47

回答

4

使用not():disabled

$('.customers input:checkbox').not(':disabled'); 

-

if ($(this).is(':checked')) { 
     $('.customers input:checkbox').not(':disabled').removeAttr('checked'); 
    } else { 
     $('.customers input:checkbox').not(':disabled').attr('checked', 'checked'); 
    } 
+0

这工作完美,谢谢! – flyersun 2013-02-15 10:14:24

相关问题