$(document).ready(function (e) {
$('.links > input').change(function () {
if ($(this).is(':checked')) {
$(this).parent().children('.subLinks').children('.subLinkCheck').children().attr('checked', true);
} else
$(this).parent().children('.subLinks').children('.subLinkCheck').children().attr('checked', false);;
});
});
它第一次工作正常。当我取消选中子复选框然后单击父复选框时,它会失败,
这是 HTML 内容
<ul id="mainLink">
<li class="links">
<input type="checkbox" />Interactive Community
<ul class="subLinks">
<li class="subLinkCheck">
<input class="1" type="checkbox" />Usability Testing</li>
<li class="subLinkCheck">
<input type="checkbox" />HFI Certification</li>
</ul>
</li>
<li class="links">
<input type="checkbox" />Heuristic Evaluations
<ul class="subLinks">
<li class="subLinkCheck">
<input type="checkbox" />Usability Testing</li>
<li class="subLinkCheck">
<input type="checkbox" />HFI Certification</li>
</ul>
</li>
</ul>