Unselect parent checkbox when all childrens are unselected in jquery

耗尽温柔 提交于 2020-01-06 07:30:48

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!