Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 无论复选框是否为选中状态,都会返回选中状态_Jquery - Fatal编程技术网

Jquery 无论复选框是否为选中状态,都会返回选中状态

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语句始终

HTML:

<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;