jstree

<script type="text/javascript"> </script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>无标题页</title>
    <script type="text/javascript">
    function OnTreeNodeChecked()
{
    var ele = window.event.srcElement;
   
    if(ele.type=='checkbox') //如果ele是复选框
    {
        var childrenDivID = ele.id.replace('CheckBox','Nodes'); //通过替换造divid
        var div = document.getElementById(childrenDivID); //查找该div是否存在
       
       
        if(div != null) //如果div存在,则表示ele是某些节点的父节点
        {
            var checkBoxs = div.getElementsByTagName('INPUT'); //查找该父节点下所有的复选框
            for(var i=0;i<checkBoxs.length;i++)
            {
                if(checkBoxs[i].type=='checkbox')
                checkBoxs[i].checked=ele.checked;
            }
        }
        else
        {
            var div = GetParentByTagName(ele,'DIV');
            var checkBoxs = div.getElementsByTagName('INPUT');
            var parentCheckBoxID = div.id.replace('Nodes','CheckBox');
            var parentCheckBox = document.getElementById(parentCheckBoxID);
            for(var i=0;i<checkBoxs.length;i++)
            {
                if(checkBoxs[i].type=='checkbox' && checkBoxs[i].checked)
                {
                    parentCheckBox.checked = true;
                    return;
                }
            }
            parentCheckBox.checked = false;
        }
       
    }
}

function GetParentByTagName(element, tagName) {
    var parent = element.parentNode;
    var upperTagName = tagName.toUpperCase();
    while (parent && (parent.tagName.toUpperCase() != upperTagName)) {
        parent = parent.parentNode ? parent.parentNode : parent.parentElement;
    }
    return parent;
}
    </script>
</head>

<body>
    <form id="form1" runat="server">
        <div>
            <asp:TreeView ID="TreeView1" runat="server" ShowCheckBoxes="All" οnclick="OnTreeNodeChecked()">
                <Nodes>
                    <asp:TreeNode SelectAction="Expand" Text="aaa" Value="aaa">
                        <asp:TreeNode SelectAction="None" Text="a1" Value="a1"></asp:TreeNode>
                        <asp:TreeNode SelectAction="None" Text="a2" Value="a2"></asp:TreeNode>
                    </asp:TreeNode>
                    <asp:TreeNode SelectAction="Expand" Text="bbb" Value="bbb">
                        <asp:TreeNode SelectAction="None" Text="b1" Value="b1"></asp:TreeNode>
                        <asp:TreeNode SelectAction="None" Text="b2" Value="b2"></asp:TreeNode>
                    </asp:TreeNode>
                < /Nodes>
            </asp:TreeView>
        </div>
    </form>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值