我的代码在 jsfiddle.net/X23LG/1/
根据代码,当我选择特定父项的所有类别时,我想隐藏特定父项 如果任何一个子元素被激活,那么父元素也应该被激活。
谢谢
最佳答案
你来了
$("input[type='checkbox']").not('.selectall').change(function () {
$('.selectall').each(function(){
var total = $(this).parent('div').siblings('ul').find('input').length;
var selected = $(this).parent('div').siblings('ul').find('input:checked').length;
if(selected >=1){$(this).attr('checked', true).parent('div').fadeOut();}else{$(this).attr('checked', false).parent('div').fadeIn();}
});
});
$("input.selectall").change(function(){
if($(this).is(':checked')){
$(this).parent('div').siblings('ul').find('input').attr('checked', true);
$(this).parent('div').fadeOut();
}else{
$(this).parent('div').siblings('ul').find('input').attr('checked', false);
$(this).parent('div').fadeIn();
}
});
关于php - 如果选择了所有子元素,则隐藏父元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21693860/