免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Treeview 只展開一個節(jié)點,其他節(jié)點關(guān)閉

asp.net 2.0 的 TreeView 控件功能雖說強大,但其客戶端控制很遜色,本文將講解 TreeView 的客戶端實現(xiàn)原理,并實現(xiàn)兩個個性化操作:
(1) 節(jié)點的全部打開和關(guān)閉;
Client Side Expand/Collapse All Nodes For ASP.NET 2.0 TreeView.
(2) 只打開一個節(jié)點(關(guān)閉其他兄弟節(jié)點)。
Just one expanded node in ASP.NET 2.0 TreeView (When a client expand one node all other will collaps)
用記事本打開頁面源代碼,可以找到一下兩個腳本引用:


<script src="/WebUI/WebResource.axd?d=RAQeBcDUNuP9iuS8q3tNEw2&t=633300220640000000" type="text/javascript"></script>
<script src="/WebUI/WebResource.axd?d=JuTdJhq3NM8Jq_RhssAkEg2&t=633300220640000000" type="text/javascript"></script>

    將"/WebUI/WebResource.axd?d=RAQeBcDUNuP9iuS8q3tNEw2&t=633300220640000000"拷到地址欄尾,下載腳本,并以 .js 命名,另一個同樣操作。分析第二個腳本文件,可以看到TreeView的很多客戶端函數(shù),其中關(guān)鍵的一個 TreeView_ToggleNode 就是客戶端點擊時觸發(fā)的事件。
    要想做個性化的操作,就得從 TreeView_ToggleNode 事件下手。我們無法更改.net封裝好的腳本,只有“重寫”。所謂的重寫就是在原來的函數(shù)之后添加一個同名函數(shù)(因為js對于同名函數(shù)只調(diào)用最后一個)。

TreeView_ToggleNode 的原函數(shù):


function TreeView_ToggleNode(data, index, node, lineType, children) {
    var img = node.childNodes[0];
    var newExpandState;
    try {
        if (children.style.display == "none") {
            children.style.display = "block";
            newExpandState = "e";
            if ((typeof(img) != "undefined") && (img != null)) {
                if (lineType == "l") {
                    img.src = data.images[15];
                }
                else if (lineType == "t") {
                    img.src = data.images[12];
                }
                else if (lineType == "-") {
                    img.src = data.images[18];
                }
                else {
                    img.src = data.images[5];
                }
                img.alt = data.collapseToolTip.replace(/\{0\}/, TreeView_GetNodeText(node));
            }
        }
        else {
            children.style.display = "none";
            newExpandState = "c";
            if ((typeof(img) != "undefined") && (img != null)) {
                if (lineType == "l") {
                    img.src = data.images[14];
                }
                else if (lineType == "t") {
                    img.src = data.images[11];
                }
                else if (lineType == "-") {
                    img.src = data.images[17];
                }
                else {
                    img.src = data.images[4];
                }
                img.alt = data.expandToolTip.replace(/\{0\}/, TreeView_GetNodeText(node));
            }
        }
    }
    catch(e) {}
    data.expandState.value = data.expandState.value.substring(0, index) + newExpandState + data.expandState.value.slice(index + 1);
}
1. 節(jié)點的全部打開和關(guān)閉(Client Side Expand/Collapse All Nodes)
<html xmlns="<head runat="server">
    <title>LeftMenu_Tree</title>
</head>
<body bgcolor="#DDEDFD">
    <form id="form1" runat="server">
        <a href="javascript:TreeviewExpandCollapseAll('<%=TreeView1.ClientID%>', true)">Expand
            All</a> <a href="javascript:TreeviewExpandCollapseAll('<%=TreeView1.ClientID%>', false)">
                Collapse All</a>
        <asp:TreeView ID="TreeView1" SkinID="tvClass" runat="server" ShowLines="true" NodeWrap="false">
        </asp:TreeView>
    </form>
</body>
</html>

<script language="javascript">
//-----------------------------------------------------------------------------
function $(s){return document.getElementById(s);}
function isNull(_sVal){return (_sVal == "" || _sVal == null || _sVal == "undefined");}

function TreeviewExpandCollapseAll(treeViewId, expandAll)
{
    var displayState = (expandAll == true ? "none" : "block");
    var treeView = $(treeViewId);
    if(treeView)
    {
        var treeLinks = treeView.getElementsByTagName("a");
        var nodeCount = treeLinks.length;
        var flag = true;
        for(i=0;i<nodeCount;i++)
        {
            if(treeLinks[i].firstChild.tagName)
            {
                if(treeLinks[i].firstChild.tagName.toLowerCase() == "img")
                {
                    var node = treeLinks[i];
                    var level = parseInt(node.id.substr(node.id.length - 1),10);
                    var childContainer = GetParentByTagName("table", node).nextSibling;
                    if(!isNull(childContainer))
                    {
                        if(flag)
                        {
                            if(childContainer.style.display == displayState)
                            {
                                TreeView_ToggleNode(eval(treeViewId +"_Data"),level,node,'r',childContainer);
                            }
                            flag = false;
                        }
                        else
                        {
                            if(childContainer.style.display == displayState)
                            {
                                TreeView_ToggleNode(eval(treeViewId +"_Data"),level,node,'l',childContainer);
                            }
                        }
                    }
                }
            }
        }//for loop ends
    }
}

function GetParentByTagName(parentTagName, childElementObj)
{
    var parent = childElementObj.parentNode;
    while(parent.tagName.toLowerCase() != parentTagName.toLowerCase())
    {
        parent = parent.parentNode;
    }
    return parent;
}
//-----------------------------------------------------------------------------
</script>

2. 只打開一個節(jié)點,關(guān)閉其他兄弟節(jié)點(Just one expanded node, all other will collaps) <html xmlns="<head runat="server">
    <title>LeftMenu_Tree</title>
</head>
<body bgcolor="#DDEDFD">
    <form id="form1" runat="server">
        <a href="javascript:TreeviewExpandCollapseAll('<%=TreeView1.ClientID%>', true)">Expand
            All</a> , <a href="javascript:TreeviewExpandCollapseAll('<%=TreeView1.ClientID%>', false)">
                Collapse All</a>
        <asp:TreeView ID="TreeView1" SkinID="tvClass" runat="server" ShowLines="true" NodeWrap="false">
        </asp:TreeView>
    </form>
</body>
</html>

<script language="javascript">
//2. 只打開一個節(jié)點,關(guān)閉其他兄弟節(jié)點(Just one expanded node, all other will collaps)
function TreeView_ToggleNode(data, index, node, lineType, children)
{
    var img = node.childNodes[0];
    var newExpandState;
    try {
        //***折疊兄弟節(jié)點(Collapse Brothers)-----
        CollapseBrothers(data,children);
        //---------------------------------------
           
        if (children.style.display == "none")
        {
            children.style.display = "block";
            newExpandState = "e";
            if ((typeof(img) != "undefined") && (img != null))
            {
                if (lineType == "l")
                {
                    img.src = data.images[15];
                }
                else if (lineType == "t")
                {
                    img.src = data.images[12];
                }
                else if (lineType == "-")
                {
                    img.src = data.images[18];
                }
                else
                {
                    img.src = data.images[5];
                }
                img.alt = data.collapseToolTip.replace(/\{0\}/, TreeView_GetNodeText(node));
            }
        }
        else
        {
            children.style.display = "none";
            newExpandState = "c";
            if ((typeof(img) != "undefined") && (img != null))
            {
                if (lineType == "l")
                {
                    img.src = data.images[14];
                }
                else if (lineType == "t")
                {
                    img.src = data.images[11];
                }
                else if (lineType == "-")
                {
                    img.src = data.images[17];
                }
                else
                {
                    img.src = data.images[4];
                }
                img.alt = data.expandToolTip.replace(/\{0\}/, TreeView_GetNodeText(node));
            }
        }
    }
    catch(e) {}
    data.expandState.value = data.expandState.value.substring(0, index) + newExpandState + data.expandState.value.slice(index + 1);
}

//折疊兄弟節(jié)點(Collapse Brothers)
function CollapseBrothers(data,childContainer)
{
    var parent = childContainer.parentNode;  
    for(i=0; i< parent.childNodes.length; i++)
    {
        if(parent.childNodes[i].tagName.toLowerCase() =="div")
        {
            if(parent.childNodes[i].id != childContainer.id)
            {
                parent.childNodes[i].style.display = "none"
            }
        }
        else if(parent.childNodes[i].tagName.toLowerCase() =="table")
        {
            var treeLinks = parent.childNodes[i].getElementsByTagName("a");           
            if(treeLinks.length > 2)
            {
                var j=0;
                if(treeLinks[j].firstChild.tagName)
                {
                    if(treeLinks[j].firstChild.tagName.toLowerCase() == "img")
                    {
                        var img = treeLinks[j].firstChild;
                        if(i==0)
                            img.src = data.images[8];
                        else if(i==parent.childNodes.length-2)
                            img.src = data.images[14];
                        else
                            img.src = data.images[11];
                    }
                }   
            }
        }       
    }
}
//-----------------------------------------------------------------------------
</script>

注意這句話:所謂的重寫就是在原來的函數(shù)之后添加一個同名函數(shù)(因為js對于同名函數(shù)只調(diào)用最后一個)。

所以上面的script放在aspx文件的最后引用!

打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
javascript之DOM操作
TreeView JavaScript控制方法研究
關(guān)于TreeView控件的節(jié)點排序
ASP.NET TREEVIEW 使用方法(2) - yyf919 - 博客園
delphi中的TreeView
TreeView 用法
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服