2

HTML:

<div id="appcheck">
  <input class="precheck" type="checkbox" /> 
  <input class="precheck" type="checkbox" />
  <input class="precheck" type="checkbox" />
</div>

チェックされていない結果を検出することになっているjQuery。not checkedチェックされているボックスの数に関係なく、常に3を返します。

$('input.precheck').each(function() {
  if($(this).not(':checked')) {
    console.log('not checked');
  }
});
4

1 に答える 1

5

isの代わりに+否定演算子を使用できます notnotブール値を返しません。jQueryオブジェクトを返し、ifステートメントは常にtrueです。

if (!$(this).is(':checked')) {

また:

if (!this.checked) {

次のようにコーディングすることもできます。

var notChecked = $('input.precheck').filter(function(){
   return !this.checked;
}).length;
于 2012-12-29T23:15:33.353 に答える