• 使用脚本改变树控件的行为


        最近在使用asp.net2.0中的TreeView控件时,遇到一个小困惑。
        此控件的节点在没有赋予链接的情况下,点击是要回发的,当然,我更希望文本节点和它前面的图标一样,点击时只有展开和收缩的动作即可,而且不希望回发到服务端,其实如果换个javascript写成的树控件最好,可是偏偏咱又是个大懒人,所以情急之下干脆写了一个方法改变TreeView控件文本节点点击的行为,特记下以备后用。 

       
     1//去除树控件节点触发回发事件,点击节点和点击展开收缩图标相同的效果
     2//如果有复选框,则点击节点与点击复选框相同效果
     3function appendExpend(nam) {
     4    //debugger
     5    var tree = document.getElementById(nam);
     6    var nodes = tree.getElementsByTagName("a");
     7    var menuname = nam.toLowerCase() + "n"//"TMenun";
     8
     9    for (i = 0; nodes[i]; i++{
    10        if (!nodes[i].id) continue;
    11        id = nodes[i].id.toLowerCase();
    12        if (id.indexOf(menuname) >= 0{
    13            var otherid = id.substr(menuname.length);
    14            var othernode = document.getElementById(nam + "t" + otherid);
    15            if (!othernode) continue;
    16            othernode.href = "";
    17            othernode.onclick = null;
    18            othernode.href = nodes[i].href;
    19        }

    20    }

    21
    22
    23    var inputs = tree.getElementsByTagName("input");
    24    var chkname = "checkbox";
    25    for (i = 0; inputs[i]; i++{
    26        if (!inputs[i].id) continue;
    27        id = inputs[i].id.toLowerCase();
    28        chkIndex = id.lastIndexOf(chkname);
    29        namIndex = id.indexOf(menuname);
    30        if (inputs[i].type == "checkbox" && chkIndex >= 0 && namIndex >= 0{
    31            otherid = id.substring(menuname.length, chkIndex);
    32            othernode = document.getElementById(nam + "t" + otherid);
    33            if (!othernode) continue;
    34            othernode.href = "";
    35            othernode.onclick = null;
    36            othernode.href = "javascript:ShiftCheck('" + inputs[i].id + "');";
    37        }

    38    }

    39}
  • 相关阅读:
    点击Notification之后收起通知栏
    Visual Studio常用的快捷键
    数据库语法二之外键
    数据引擎 创建表完整语法,字段类型,约束条件
    数据库 tcp协程实现并发 回调函数
    GIL以及协程
    进程,互斥锁,生产者消费者,线程
    udp协议,进程(同步,异步)
    单例模式,网络编程之tcp协议以及粘包问题
    网络编程
  • 原文地址:https://www.cnblogs.com/BeanHsiang/p/1340385.html
Copyright © 2020-2023  润新知