ch(e) {}
data.expandState.value = data.expandState.value.substring(0, index) + newExpandState + data.expandState.value.slice(index + 1);
}
节点的全部打开和关闭(Client Side Expand/Collapse All Nodes)
<html xmlns="http://www.w3.org/1999/xhtml">
<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&g