[英]How to check if at least one checkbox is checked from list of checkboxes with it name attribute as array
I have a div and inside that div i have check boxes with name attribute as an array, now i want to heck if at least one check box is checked. 我有一个div,在该div内,我有一个复选框,其名称属性为数组,现在我想知道如果至少选中一个复选框。
<div id="check_lists">
<input type="checkbox" name="usernames[]" value="1">
<input type="checkbox" name="usernames[]" value="2">
<input type="checkbox" name="usernames[]" value="3">
<input type="checkbox" name="usernames[]" value="3">
</div>
You can use attribute equals selector with .is() and :checked-selector 您可以将属性等于选择器与.is()和:checked-selector一起使用
if($('input[name="usernames[]"]').is(':checked')){
//at least one is checked
}
use length
to find at least one check box is checked 使用
length
查找至少一个复选框
if($('#check_lists input[type=checkbox][name="usernames[]"]:checked').length){
// at least one check box is checked
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.