首页 ┆ 网站地图 ┆ 在线留言 ┆ 游戏资讯 ┆ 资源下载 ┆ 端午节祝福 ┆ 迅雷在线影视
设为首页
加入收藏
联系我们
高级搜索
您当前的位置: 主页>NET专区>ASP.NET>javascript实现TreeView 控件不回发操作
javascript实现TreeView 控件不回发操作
来源: 发布时间:2008-06-02 发布人: 浏览: 人次   字体: [ ]  

今天在论坛看到一个问题,问的是如何实现 TreeView 控件在不回发的情况下,实现各种功能。既然不要求回发,只能使用客户端的脚本来实现了,下面就是完整的代码。
<%@ Page Language="C#" AutoEventWireup="true" %>
<!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="IT知道网之.NET专区">
     <asp:TreeNode Text="">
      <asp:TreeNode Text="IT知道网之Silverlight">
       <asp:TreeNode Text="java技术">
        <asp:TreeNode Text="php技术"></asp:TreeNode>
       </asp:TreeNode>
      </asp:TreeNode>
     </asp:TreeNode>
     <asp:TreeNode Text="c/c++技术">
      <asp:TreeNode Text="IT知道网之数据库">
       <asp:TreeNode Text="软件工程"></asp:TreeNode>
      </asp:TreeNode>
     </asp:TreeNode>
     <asp:TreeNode Text="软件工程">
      <asp:TreeNode Text="网站推广"></asp:TreeNode>
     </asp:TreeNode>
    </asp:TreeNode>
    <asp:TreeNode Text="图形图像"></asp:TreeNode>
    <asp:TreeNode Text="网页特效">
     <asp:TreeNode Text="it健康">
      <asp:TreeNode Text="it故事">
       <asp:TreeNode Text="IT知道网之硬件资讯"></asp:TreeNode>
      </asp:TreeNode>
     </asp:TreeNode>
    </asp:TreeNode>
   </Nodes>
  </asp:TreeView>
 </div>
 </form>
</body>
</html>


相 关 文 章   发布商链接
·实现多列,带图片的DropDownList代码
·asp.net实现将Excel文件导入到SQL数...
·asp.net动态生成txt文本文件供用户下...
·asp.net读取Xml文件并进行DropDownLi...
·asp.net文件上传大小限制的控制
·在Ie中保存图片时出现"800700de错误"...
·ASP.NET中的doPostBack脚本函数的应...
·怎样在Asp.net中实现当前网站的访问...
·Asp.net进行ajax开发操作下的异常几...
·asp.net无刷新上传文件
 §最新评论:(评论内容只代表网友观点,与本站立场无关!)
网名: 验证码:  【所有评论】【↑返回顶部
评 分: 12 345
评论内容:(不能超过500字,请自觉遵守互联网相关政策法规。[按 Ctrl+Enter 可直接提交]
注意:请勿在本站发布政治话题、色情及违反法律的内容。
IT知道网 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。
推 荐 文 章
·如何实现在DataList控件中的D...
·实例讲解asp.net生成高质量缩
·asp.net适用于IE或FireFox的...
·举例详解C#代码与javaScript...
·asp.net无刷新上传文件
·在Ie中保存图片时出现"800700...
·asp.net文件上传大小限制的控
·asp.net动态生成txt文本文件...
·asp.net实现将Excel文件导入...
·实现多列,带图片的DropDownLi...
·ASP.NET配置Word的操作权限
·让FileUpload控件在IE和FireF...
·ASP.NET实现Office文档的分类
·asp.net文件下载显示进度条的
·实例讲解ASP.NET上传大文件的
热 门 文 章
·asp.net(C#)上传下载及文件管...
·图解asp.net如何用excel做报...
·asp.net无刷新上传文件
·Asp.Net防止刷新重复提交数据...
·asp.net实现将Excel文件导入...
·asp.net中Web.Config配置文件...
·ASP.NET取得物理路径和虚拟路...
·asp.net(c#)生成验证码代码,...
·asp.net页面回传与js调用服务...
·asp.net(C#版)实现登录验证码...
·DataGrid中DropDownList触发S...
·ASP.net 实现批量数据更新或...
·asp.net中DataBinder.Eval的...
·asp.net可输入的下拉框复合控...
·asp.net中常见的几种日历控件...
网站首页 - 关于本站 - 加入收藏 - 网站地图 - 友情连接 - 在线留言 - 联系我们 - 返回顶部
Copyright © 2007 IT知道网.[冀ICP备07026896号]. All Rights Reserved .