Basically I have code that checks if any checkboxes with a given class are selected. If one of those isn't, another checkbox doesn't get selected (parent).
Logic
for each checkbox
{
if this isn't checked then uncheck checkbox A
if all siblings aren't checked uncheck checkbox A
// recursion for grandparents as well.
}
Is there a Any() function or All() function in jQuery to do this?
Any help would be greatl开发者_StackOverflow社区y appreciated.
Regards, Jamie
Why don't you do it like this:
when a chebox changes state, count all the checkboxes, and count all the checked checkboxes, and then compare the value's. if they are the same, then they are all checked ...
$(':checkbox:not(:checked)').each(function() {
});
I don't get the internal logic. Checkbox A is some other checkbox in which we don't know the state. You want to uncheck it if any checkbox is unchecked, then you want to uncheck it again if any of its siblings aren't checked as well?
Are we talking about your standard 'select all' checkbox or some sort of tree?
if($(':checkbox:not(#checkbox_A):not(:checked)').length > 0) {
$('#checkbox_A').attr('checked', '');
}
精彩评论