HTML:
<div id="appcheck">
<input class="precheck" type="checkbox" />
<input class="precheck" type="checkbox" />
<input class="precheck" type="checkbox" />
</div>
应该发现未经检查结果的jQuery。无论检查了多少个盒子,总是返回3 not checked
。
$('input.precheck').each(function() {
if($(this).not(':checked')) {
console.log('not checked');
}
});
答案 0 :(得分:5)
您可以使用is
+否定运算符代替not
。 not
不返回布尔值;它返回一个jQuery对象,你的if语句总是为真。
if (!$(this).is(':checked')) {
或:
if (!this.checked) {
您也可以编码:
var notChecked = $('input.precheck').filter(function(){
return !this.checked;
}).length;