HTML:
<div id="appcheck">
<input class="precheck" type="checkbox" />
<input class="precheck" type="checkbox" />
<input class="precheck" type="checkbox" />
</div>
应该发现未经检查的结果的 jQuery。无论选中多少个框,始终返回 3 未选中
。
$('input.precheck').each(function() {
if($(this).not(':checked')) {
console.log('not checked');
}
});
最佳答案
您可以使用is
+ 否定运算符来代替not
。 not
不返回 bool 值;它返回一个 jQuery 对象,并且您的 if 语句始终为 true。
if (!$(this).is(':checked')) {
或者:
if (!this.checked) {
您还可以编码:
var notChecked = $('input.precheck').filter(function(){
return !this.checked;
}).length;
关于jquery - 复选框总是返回选中状态,无论是否选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14086748/