简体   繁体   English

如何检查复选框列表中是否至少选中了一个复选框,其名称属性为数组

[英]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.

相关问题 如何从复选框数组中检查至少一个复选框,并且复选框中的文本区域不为空白,且其值为“ other”? - How to check at least one checkbox is checked from the array of checkboxes and the text area is not blank on checkbox with value “other” is checked? 如何检查多个复选框中是否选中了至少一个复选框? - How to check that at least one checkbox is checked in multiple checkboxes? 如何检查用户是否已使用jQuery / Javascript选中了一组复选框中的至少一个复选框? - How to check whether user has checked at least one checkbox from a group of checkboxes using jQuery/Javascript? 如何检查表单中是否至少选中了一个复选框? - How to check if at least one checkbox is checked in the form? 如何验证在每组复选框中至少选中了一个复选框 - How to validate that at least one checkbox is checked in each set of checkboxes 检查是否至少选中了一个复选框 - Check if at least one checkbox is checked 当未选中组中的复选框或至少选中一个复选框,然后为相关的div添加一个类时,如何捕获事件? - How to catch the event when none of checkboxes from group is checked or at least one checkbox is checked and then add a class for the related div? 如何创建 function 以检查是否至少选中了一个复选框? - How to create function to check if at least one checkbox is checked? 如何检查至少一个复选框 - How do I check at least one checkbox is checked 如何检查每组复选框至少选中一个 - How to check each group of checkbox is checked at least one
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM