2014-09-25 26 views
0

我需要找到所有没有特定类的复选框。 这就是我所拥有的,这是行不通的。我需要检查所有没有名为“功能”的复选框。获取所有没有特定类的复选框

var value = 'features'; 
$('input:checkbox[class!="'+value+'"]').attr("checked", ""); 

回答

2

使用:not

var checkBoxes = $("input:checkbox:not(." + value + ")"); 
+0

+1简单和快速的答案。 – Lrrr 2014-09-25 14:35:30

1

这是你想要什么:fiddle here!

var cname = "features"; 
 
$('input:checkbox:not(.'+cname+')').each(function() { 
 
     $(this).prop('checked', true); 
 
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<input type="checkbox" name="vehicle" value="one" class="features">one<br> 
 
<input type="checkbox" name="vehicle" value="two" class="two">two<br> 
 
<input type="checkbox" name="vehicle" value="three" class="three">three<br> 
 
<input type="checkbox" name="vehicle" value="four" class="features" > four