Jquery检查是否检查了所有除一个复选框

时间:2014-05-03 10:37:23

标签: jquery forms

我有一组由class ="复选框"指定的复选框。我想检查除了id =" donotcheck"之外的所有复选框。检查。如何更改以下代码才能执行此操作?

$('.checkbox[checked!=true]').length == 0

2 个答案:

答案 0 :(得分:1)

尝试类似:

var $boxes = $('.checkbox'),
    numberOfCheckedBoxes = $boxes.filter(':checked').length,
    numberOfCheckableBoxes = $boxes.not('#donotcheck').length,
    numberOfUncheckableBoxes = $boxes.filter('#donotcheck:checked').length;

if (numberOfCheckedBoxes === numberOfCheckableBoxes && numberOfUncheckableBoxes === 0) {
    alert ('All good.');
} else {
    alert ('ERROR!');
}

在这里演示:http://jsfiddle.net/2NcLu/1/

答案 1 :(得分:-1)

试试这个 JSFIDDLE

<input type="checkbox" class="checkbox" />
<input type="checkbox" class="checkbox" />
<input type="checkbox" class="checkbox"  id="donotcheck" />
<input type="checkbox" class="checkbox" />
<input type="checkbox" class="checkbox" />

<button id="testButton">test</button>

var testButton = $('#testButton');

testButton.on('click', function() {
    if($(".checkbox:checked:not(#donotcheck)").length ==$(".checkbox:not(#donotcheck)").length && !$("#donotcheck").is(":checked")){
  alert("all Except One Checkbox is Checked");
    } else {
        alert('error...')
    }
});