问题
Refering to this previous question :
Sub selecting (checking) checkboxes that have a specified tag in Jquery
And the associated fiddle : http://jsfiddle.net/YSSps/11/
$(document).ready(function(){
$checkboxes = $("span.indenter:empty").parent().prev().children().children();
$checkboxes.click(function(){
var $t = $(this);
var checked = $t.is(':checked');
var $tr = $t.parent().parent().parent();
do { $tr = $tr.next();
if(!$tr.length) return;
var child = !$tr.children(":nth-child(2)").children("span").is(":empty");
if( child )
$tr.children(":nth-child(1)").children().children().prop('checked',checked);
} while(child);
});
$children = $("span.indenter").parent().prev().children().children();
$children.click(function() {
if($children.parent().parent().next().children().text() == '-- ')
alert('it is a children');
});
});
I would like to have the following behaviour :
When the last child is unchecked to uncheck the parent as well so user can only check the children when the parent is checked and not be able to check the parent only.
来源:https://stackoverflow.com/questions/14851614/unselect-parent-checkbox-when-all-childrens-are-unselected-in-jquery