• 使用脚本改变树控件的行为 (转)点文本 收..


    最近在使用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}
  • 相关阅读:
    async和await
    Promise
    初始flexbox
    制作一个slider动画
    初探React编程逻辑(结合业务需求)
    原型(prototype)和继承(inherit)
    什么是词法环境(lexical scope)
    typeScript是什么
    typeScript基础类型
    原型,原型链,call/apply
  • 原文地址:https://www.cnblogs.com/pchgo/p/1411649.html
Copyright © 2020-2023  润新知