I have two sets of check boxes. At least one in each group has to be checked. How do I accomplish this with Jquery? Here is my link to JS Fiddle:
http://开发者_开发技巧jsfiddle.net/TknCq/
do a:
$('ul:has(input[type="checkbox"]:checked)').length == 2
where 2 is the number of groups. It gives you the number of ul's that contain a checked input that has to be 2 in this case ;) So it checks that every ul
that contains checkboxes
has at least one checked
.
fiddle here
You can grab all the inputs in the wrappers that have an attribute checked and if the length > 0 you have at least one checkbox checked:
var checkboxes_claimStatus = $("#field-claimStatus-wrapper").find("input:checked");
if(checkboxes_claimStatus.length)
{
alert('checked');
}
Do the same for the other group.
Try this.
if($("#field-claimType-wrapper input:checked").length > 0){
}
if($("#field-claimStatus-wrapper input:checked").length > 0){
}
Use something like this...
$("input[name='claimType']:checked").size() > 0 && $("input[name='claimStatus']:checked").size() > 0
checking if the checked checkbox count in both groups is greater than 0
Here is the updated jsfiddle link
精彩评论