如果所有的子节点都没有被选中,我希望取消选中父节点。
我有以下jQuery脚本。但是当我取消选中任何子项时,父项也会被取消选中。它应该判断所有子项是否都未选中,然后再取消选中父项。
<ul id="treeList">
<li>
<input type="checkbox" name="selectedRole">
Application Manager
<ul>
<li>
<input type="checkbox" name="selectedRole">
Application Manager Panel
</li>
<li>
<input type="checkbox" name="selectedRole">
Client Role
<ul>
<li>
<input type="checkbox" name="selectedRole">
Client Task 1
</li>
<li>
<input type="checkbox" name="selectedRole">
Client Task 2
</li>
</ul>
</li>
</ul>
</li>
我有以下jQuery脚本。但是当我取消选中任何子项时,父项也会被取消选中。它应该判断所有子项是否都未选中,然后再取消选中父项。
jQuery.each(jQuery('#treeList ul li').find(':checkbox'), function(){
jQuery(this).change(function (){
if (jQuery(this).is(':checked')) {
jQuery(this).parents('ul').siblings('input:checkbox').attr('checked', true);
}else{
jQuery(this).parents('ul').siblings('input:checkbox').attr('checked', false);
}
});
});
trigger
更改应该解决它。更新的示例。 - Niklas