我有一组由class ="复选框"指定的复选框。我想检查除了id =" donotcheck"之外的所有复选框。检查。如何更改以下代码才能执行此操作?
$('.checkbox[checked!=true]').length == 0
答案 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!');
}
答案 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...')
}
});