Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 家庭问题_Jquery_Checkbox - Fatal编程技术网

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();
        }  
    });

你得到答案了吗??