zoukankan      html  css  js  c++  java
  • 使用脚本改变树控件的行为

        最近在使用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}
  • 相关阅读:
    电子海图开发一百篇第五十五篇-电子江图传输规范 数据模型
    天气可视化,海浪,温度图层的绘制,温度热力图的可视化
    全球潮汐数据API使用方法,潮汐数据查询
    海洋气象数据可视化,以流场的方式显示风场图,海洋气象API使用
    g++ 编译module失败
    编译gcc error-*** LIBRARY_PATH shouldn‘t contain the current directory when *** building gcc.
    windows两种自启动的区别
    windows多线程加锁
    windows server 2012不显示此电脑
    pthread_cond_wait
  • 原文地址:https://www.cnblogs.com/BeanHsiang/p/1340385.html
Copyright © 2011-2022 走看看