juery 选中 treeview 所有子节点 和父节点

juery 选中 treeview 所有子节点 和父节点

 function OnTreeNodeChecked() {
            var ele = event.srcElement;
            if (ele.type == 'checkbox') {
                var divId = ele.id.replace('CheckBox', 'Nodes');
                $("#" + divId).find("input[type=checkbox]").attr("checked", ele.checked);
                OnTreeNodeChildChecked(ele);

            }
        }

        function OnTreeNodeChildChecked(ele) {
            //自动处理上级
            try {
                var parentDiv = $(ele).parent().parent().parent().parent().parent();
                //  ele.parentElement.parentElement.parentElement.parentElement.parentElement;
                if (typeof (parentDiv.attr('id')) == 'undefined')
                    return;
                var parentChkBox = document.getElementById(parentDiv.attr('id').replace('Nodes', 'CheckBox'));
                if (parentChkBox != null) {
                    var ChildsChkAll = true;
//                    var Boxs = parentDiv.getElementsByTagName('INPUT');
//                    for (var i = 0; i < Boxs.length; i++) {
//                        if (Boxs[i].type == 'checkbox' && Boxs[i].checked == false) {
//                            ChildsChkAll = false;
//                        }
//                    }
                    parentChkBox.checked = ChildsChkAll;
                    OnTreeNodeChildChecked(parentChkBox);
                }
            }
            catch (e) {
                alert(e.message);
            }
        }

你可能感兴趣的:(juery 选中 treeview 所有子节点 和父节点)