Jquery 无论复选框是否为选中状态,都会返回选中状态
HTML:Jquery 无论复选框是否为选中状态,都会返回选中状态,jquery,Jquery,HTML: <div id="appcheck"> <input class="precheck" type="checkbox" /> <input class="precheck" type="checkbox" /> <input class="precheck" type="checkbox" /> </div> 您可以使用is+否定运算符代替notnot不返回布尔值;它返回一个jQuery对象,并且if语句始终
<div id="appcheck">
<input class="precheck" type="checkbox" />
<input class="precheck" type="checkbox" />
<input class="precheck" type="checkbox" />
</div>
您可以使用
is
+否定运算符代替not
not
不返回布尔值;它返回一个jQuery对象,并且if语句始终为true
if (!$(this).is(':checked')) {
或:
您还可以编写以下代码:
var notChecked = $('input.precheck').filter(function(){
return !this.checked;
}).length;
如果我没有弄错的话,
$(this).not(“:checked”)
作为jQuery对象是“truthy”,因此无论它代表多少个元素,它都将满足If
。另一方面,等函数返回布尔值。这些都被很好地涵盖了,准备好让你们阅读。@LightnessRacesinOrbit,这解释了很多。谢谢
if (!this.checked) {
var notChecked = $('input.precheck').filter(function(){
return !this.checked;
}).length;