[英]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 if at least one checkbox is checked from list of checkboxes with it name attribute as array
我有一個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>
您可以將屬性等於選擇器與.is()和:checked-selector一起使用
if($('input[name="usernames[]"]').is(':checked')){
//at least one 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.