TreeView 控件之不回发操作
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("刷新标记:" + DateTime.Now.Ticks.ToString());
TreeView1.Attributes.Add("onclick", "getNode(event);");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>TreeView 控件之不回发操作</title>
<script type="text/javascript">
var foo = null;
function getNode(evt)
{
evt1 = window.event ? window.event.srcElement : evt.target;
if(evt1.tagName && evt1.tagName != "INPUT")
{
if(evt1.tagName == "IMG")
{
return true;
}
else
{
if(foo) foo.style.color="#00F"; //最初的颜色
evt1.style.color="#f0f0f0"; //如果要其他单击变换颜色,调整这3的位置即可,应该不用再说了吧???
foo = evt1;
var sb = evt1.previousSibling;
if(sb.tagName == "INPUT")
{
var imgPlus = document.getElementById(sb.id.replace(/CheckBox/gi,""));
if(imgPlus)
{
eval(imgPlus.href)
}
}
if(window.event)
{
window.event.returnValue=false;
return false;
}
else
{
evt.preventDefault();
evt.stopPropagation();
}
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TreeView ID="TreeView1" runat="server" EnableClientScript="True" ShowCheckBoxes="All" ShowLines="True">
<Nodes>
<asp:TreeNode Text="ASP.NET">
<asp:TreeNode Text="ASP.NET MVC">
<asp:TreeNode Text="Silverlight">
<asp:TreeNode Text="LINQ">
<asp:TreeNode Text="XML"></asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="XSL">
<asp:TreeNode Text="C#">
<asp:TreeNode Text="VB.NET"></asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="Blog">
<asp:TreeNode Text="新闻"></asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="javaScript"></asp:TreeNode>
<asp:TreeNode Text="HTML DOM">
<asp:TreeNode Text="VSTS">
<asp:TreeNode Text="Live">
<asp:TreeNode Text="Book On Line"></asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
</div>
</form>
</body>
</html>
作者:mFrog(mFrog的技术博客)
出处:http://mFrog.cnblogs.com/
本文版权由作者全部保留,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。