ID在您的文档中必须是唯一的,这意味着您不应该这样做:
<input type="checkbox" name="chk[]" id="chk[]" value="Apples" /><input type="checkbox" name="chk[]" id="chk[]" value="Bananas" />
而是删除ID,然后按名称或包含元素选择它们:
<fieldset id="checkArray"> <input type="checkbox" name="chk[]" value="Apples" /> <input type="checkbox" name="chk[]" value="Bananas" /></fieldset>
现在是jQuery:
var atLeastoneIsChecked = $('#checkArray:checkbox:checked').length > 0;//there should be no space between identifier and selector// or, without the container:var atLeastoneIsChecked = $('input[name="chk[]"]:checked').length > 0;


