TreeView 客户端响应点击的方法

  1. 服务器端

protected void Page_Load(object sender, EventArgs e)
{
        this.TreeView1.Attributes.Add("OnClick", "ClickNode()");
}

 

或直接在页面设计中设置:

<asp:TreeView ID="TreeView1" OnClick="ClickNode()" runat="server">
    </asp:TreeView>

 

2. 客户端

<script type="text/javascript">
 function ClickNode()
 {
     var Obj=event.srcElement;    
     var s = Obj.toString();
     var lastIndex = s.lastIndexOf('\\');
    
     lastIndex = lastIndex + 1;
     if (lastIndex == 0)
     {
         lastIndex = s.indexOf("','s") + 4;
     }
     var nodeValue = s.substring(lastIndex);
     var nodeText = Obj.innerText;
//     if(Obj.tagName == "A" || Obj.tagName== "a")        
//     {            
//         alert(Obj.innerText);  
//     }
 } </script>

posted @ 2009-12-08 18:19  Ken-Cai  阅读(217)  评论(0编辑  收藏  举报