cuisky

导航

asp.net2.0中,实现treeview中选择父级checkbox时,子级连动 整理转载

javascript 函数如下:

function client_OnTreeNodeChecked()
    {
        var obj = window.event.srcElement;
        var treeNodeFound = false;
        var checkedState;
        if (obj.tagName == "INPUT" && obj.type == "checkbox")
        {
            var treeNode = obj;
            checkedState = treeNode.checked;
            do
            {
             obj = obj.parentElement;
            }
         while (obj.tagName != "TABLE")
            var parentTreeLevel = obj.rows[0].cells.length;
            var parentTreeNode = obj.rows[0].cells[0];
            var tables = obj.parentElement.getElementsByTagName("TABLE");
            var numTables = tables.length
            if (numTables >= 1)
            {
                for (i=0; i < numTables; i++)
                {
                    if (tables[i] == obj)
                    {
                        treeNodeFound = true;
                        i++;
                        if (i == numTables)
                        {
                            return;
                        }
                    }
                    if (treeNodeFound == true)
                    {
                        var childTreeLevel = tables[i].rows[0].cells.length;
                        if (childTreeLevel > parentTreeLevel)
                        {
                            var cell = tables[i].rows[0].cells[childTreeLevel - 1];
                            var inputs = cell.getElementsByTagName("INPUT");
                            inputs[0].checked = checkedState;
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }
        }
    }

在网面的TreeView代码中增加 onclick="client_OnTreeNodeChecked();"即OK了

posted on 2006-10-12 12:43  风风  阅读(1698)  评论(1编辑  收藏  举报