Jquery 家庭问题
我在这里工作时有复选框 我的问题是:当我单独勾选所有的子复选框时,父复选框没有被勾选,也没有消失Jquery 家庭问题,jquery,checkbox,Jquery,Checkbox,我在这里工作时有复选框 我的问题是:当我单独勾选所有的子复选框时,父复选框没有被勾选,也没有消失 $(document).ready(function() { $(".pc-box").click(function() { if (this.checked) { $(this).closest("li").find(".cc-box").prop("checked", true); $(this).parent()
$(document).ready(function() {
$(".pc-box").click(function() {
if (this.checked) {
$(this).closest("li").find(".cc-box").prop("checked", true);
$(this).parent().fadeOut();
}
});
$(".cc-box").click(function() {
if (!this.checked)
$(this).closest("ul").prev().fadeIn().find(".pc-box").prop("checked", false);
});
});
您必须使用
parents()
而不是parent()
parent()
用于指向直接父对象,而parents(“#选择器”)用于指向链中的父对象,除非找到选择器
使用此代码:
$(".pc-box").click(function() {
if (this.checked) {
$(this).parents("li").find(".cc-box").prop("checked", true);
$(this).parents('li').fadeOut();
}
});
你得到答案了吗??