<SCRIPT type=text/javascript>
var tree = null;
var root = new TreeNode('系统菜单');var fun1 = new TreeNode('客户资料');
var fun2 = new TreeNode('新增客户', 'khzl/kh_edit.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun1.add(fun2);
var fun3 = new TreeNode('来访客户', 'khzl/lf_kh_list.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun1.add(fun3);
var fun4 = new TreeNode('信息来源', 'khzl/infor_source.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun1.add(fun4);
var fun5 = new TreeNode('今日预约', 'khzl/today_yy_kh_list.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun1.add(fun5);
var fun6 = new TreeNode('客户分配', 'khzl/kh_fp.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun1.add(fun6);
var fun7 = new TreeNode('客户回收', 'khzl/kh_hs.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun1.add(fun7);root.add(fun1);
var fun8 = new TreeNode('课程顾问');
var fun9 = new TreeNode('我的客户', 'kcgw/my_all_kh_list.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun8.add(fun9);
var fun10 = new TreeNode('new客户', 'kcgw/my_new_kh_list.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun8.add(fun10);
var fun11 = new TreeNode('我的预约', 'kcgw/my_today_yy.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun8.add(fun11);
var fun12 = new TreeNode('客户分组', 'kcgw/my_students.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun8.add(fun12);
var fun13 = new TreeNode('客户统计', 'kcgw/my_kh_count.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun8.add(fun13);
var fun14 = new TreeNode('统计', 'kcgw/my_all_count.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun8.add(fun14);
var fun15 = new TreeNode('所有预约', 'kcgw/yy_kh_list.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun8.add(fun15);root.add(fun8);
var fun16 = new TreeNode('试听管理');
var fun17 = new TreeNode('所有视听', 'listen/all_try_listen.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun16.add(fun17);
var fun18 = new TreeNode('今日试听', 'listen/today_try_listen.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun16.add(fun18);
var fun19 = new TreeNode('试听课程', 'listen/try_listen_lesson.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun16.add(fun19);root.add(fun16);
var fun20 = new TreeNode('合同管理');
var fun21 = new TreeNode('所有合同', 'MessageMgr.aspx', 'tree_node.gif', null, 'tree_node.gif', null);fun20.add(fun21);
var fun22 = new TreeNode('信箱', 'MailBox.aspx', 'tree_node.gif', null, 'tree_node.gif', null);fun20.add(fun22);
var fun23 = new TreeNode('信箱', 'MailBox.aspx', 'tree_node.gif', null, 'tree_node.gif', null);fun20.add(fun23);
var fun24 = new TreeNode('信箱', 'MailBox.aspx', 'tree_node.gif', null, 'tree_node.gif', null);fun20.add(fun24);
var fun25 = new TreeNode('信箱', 'MailBox.aspx', 'tree_node.gif', null, 'tree_node.gif', null);fun20.add(fun25);root.add(fun20);
var fun26 = new TreeNode('财务管理');
var fun27 = new TreeNode('收入合计', 'RoleMgr.aspx', 'tree_node.gif', null, 'tree_node.gif', null);fun26.add(fun27);
var fun28 = new TreeNode('收入明细', 'LoginLog.aspx', 'tree_node.gif', null, 'tree_node.gif', null);fun26.add(fun28);
var fun29 = new TreeNode('收入日志', 'OperationLog.aspx', 'tree_node.gif', null, 'tree_node.gif', null);fun26.add(fun29);
var fun30 = new TreeNode('收入图表', 'MenuSort.aspx', 'tree_node.gif', null, 'tree_node.gif', null);fun26.add(fun30);root.add(fun26);
var fun31 = new TreeNode('Follow up');
var fun32 = new TreeNode('签到签退', 'SignInOrOut.aspx', 'tree_node.gif', null, 'tree_node.gif', null);fun31.add(fun32);
var fun33 = new TreeNode('考勤查询', 'HistoryQuery.aspx', 'tree_node.gif', null, 'tree_node.gif', null);fun31.add(fun33);
var fun34 = new TreeNode('考勤统计', 'TimeStatistics.aspx', 'tree_node.gif', null, 'tree_node.gif', null);fun31.add(fun34);root.add(fun31);
var fun35 = new TreeNode('课程安排');
var fun36 = new TreeNode('今日课程', 'listen/today_lesson.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun35.add(fun36);
var fun37 = new TreeNode('所有课程', 'listen/all_lesson.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun35.add(fun37);
var fun38 = new TreeNode('已开课程', 'listen/start_lesson.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun35.add(fun38);root.add(fun35);
var fun39 = new TreeNode('用户管理');
var fun40 = new TreeNode('所有用户', 'user_mange/all_user.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun39.add(fun40);
var fun41 = new TreeNode('添加/删除', 'user_mange/add_del.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun39.add(fun41);
var fun42 = new TreeNode('部门/权限', 'user_mange/depart_rule.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun39.add(fun42);root.add(fun39);
var fun43 = new TreeNode('数据统计');
var fun44 = new TreeNode('全部数据', 'all_data.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun43.add(fun44);
var fun45 = new TreeNode('部门管理', 'all_.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun43.add(fun45);
var fun46 = new TreeNode('本月统计', 'this_mounth.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun43.add(fun46);root.add(fun43);
var fun47 = new TreeNode('个人设置');
var fun48 = new TreeNode('我的客户', 'edit.asp', 'tree_node.gif', null, 'tree_node.gif', null);fun47.add(fun48);
var fun49 = new TreeNode('部门管理', 'DepartmentMgr.aspx', 'tree_node.gif', null, 'tree_node.gif', null);fun47.add(fun49);
var fun50 = new TreeNode('员工管理', 'EmployeeMgr.aspx', 'tree_node.gif', null, 'tree_node.gif', null);fun47.add(fun50);
root.add(fun47);
tree = new Tree(root);
tree.show('menuTree')
</SCRIPT>

解决方案 »

  1.   

    function Tree(rootNode) {
    var $ = this;
    this.root = rootNode;

    this.show = function(container) {
    $.update($.root);
    this.root.expand();

    if(container.tagName)
    container.appendChild($.root.container);
    else if(typeof container == "string")
    document.getElementById(container).appendChild($.root.container);
    }

    this.update = function(parent) {
    parent.indent();
    for (var i = 0; i < parent.children.length; i++) {
    parent.children[i].level = parent.level + 1;
    for (var j = 0; j < parent.ancestor.length; j++) {
    parent.children[i].ancestor.push(parent.ancestor[j]);
    }
    parent.children[i].ancestor.push(parent);
    $.update(parent.children[i]);
    }
    }
    }
    var currentNode = null;
    function TreeNode(text, url, iconOpen, iconOpenHover, iconClosed, iconClosedHover) {
    var $ = this;
    this.level = 0;
    this.children = [];
    this.parent = null;
    this.status = "CLOSED";
    this.ancestor = [];
    this.isHover = false;

    this.PATH = "images/tree/";
    this.COLLAPSED = this.PATH + "arrow_collapsed.gif";
    this.EXPANDED = this.PATH + "arrow_expanded.gif";
    this.COLLAPSED_HOVER = this.PATH + "arrow_collapsed_hover.gif";
    this.EXPANDED_HOVER = this.PATH + "arrow_expanded_hover.gif";
    this.CATEGORYOPEN = this.PATH + (iconOpen ? iconOpen : "folder_open.gif");
    this.CATEGORYOPEN_HOVER = this.CATEGORYOPEN;
    this.CATEGORYCLOSED = this.PATH + (iconClosed ? iconClosed : "folder_closed.gif");
    this.CATEGORYCLOSED_HOVER = this.CATEGORYCLOSED;
    this.EMPTY = this.PATH + "empty.gif"; this.container = document.createElement("DIV");
    this.content = document.createElement("DIV");
    this.indentSpace = document.createElement("SPAN");
    this.statusIcon = document.createElement("IMG");
    this.node = document.createElement("SPAN");
    this.nodeIcon = document.createElement("IMG");
    this.label = document.createElement("A");
    this.container.appendChild(this.content);
    this.content.appendChild(this.indentSpace);
    this.content.appendChild(this.statusIcon);
    this.content.appendChild(this.node);
    this.node.appendChild(this.nodeIcon);
    this.node.appendChild(this.label); this.container.style.display = "block";
    this.statusIcon.src = this.COLLAPSED;
    this.nodeIcon.src = this.CATEGORYCLOSED;
    this.nodeIcon.align = "absmiddle";
    this.statusIcon.align = "absmiddle";
    this.statusIcon.style.cursor = "default";
    this.node.style.cursor = "default";
    this.label.style.lineHeight = "20px";
    this.label.style.fontSize = "12px";
    this.label.style.display = "inline-block";
    this.label.style.backgroundImage = "url(" + this.BG + ")";
    this.label.style.backgroundRepeat = "repeat-x";
    this.label.innerHTML = text;

    if (url) {
        this.label.href = url;
        this.label.target = "mainFrame";
    } this.add = function(child) {
    this.container.appendChild(child.container);
    this.children.push(child);
    child.parent = this;
    }

    this.remove = function(child) {
    child.container.removeNode(true);
    var temp = [];
    for (var i = 0; i < this.children.length; i++) {
    if (this.children[i] != child) {
    temp.push(this.children[i]);
    } else {
    continue;
    }
    }
    this.children = temp;
    } this.hidden = function() {
    this.container.style.display = "none";
    } this.show = function() {
    this.container.style.display = "block";
    } this.getAncestor = function(level) {
    if (this.level == level)
    return this;
    for (var i = 0; i < $.ancestor.length; i++) {
    if ($.ancestor[i].level == level) {
    return $.ancestor[i];
    }
    }
    return null;
    }

    this.contains = function(node) {
    for (var i = 0; i < $.children.length; i++) {
    if ($.children[i] == node) {
    return true;
    }
    $.children[i].contains(node);
    }
    return false;
    }

    this.indent = function() {
    this.indentSpace.innerHTML = "";
    for (var i = 0; i < this.level; i++) {
    var indentImg = document.createElement("IMG");
    indentImg.src = this.EMPTY;
    indentImg.align = "absmiddle";
    this.indentSpace.appendChild(indentImg);
    }
    this.collapse();
    }

    this.setIcon = function() {
    this.nodeIcon = this.status == "CLOSED" ? 
    ($.isHover ? $.CATEGORYCLOSED_HOVER : $.CATEGORYCLOSED) : 
    ($.isHover ? $.CATEGORYOPEN_HOVER : $.CATEGORYOPEN);
    }

    this.collapse = function() {
    for (var i = 0; $.children && i < $.children.length; i++) {
    $.children[i].hidden();
    }
    $.statusIcon.src = $.COLLAPSED;
    $.nodeIcon.src = $.CATEGORYCLOSED;
    $.status = "CLOSED";
    }

    this.expand = function() {
    for (var i = 0; $.children && i < $.children.length; i++) {
    $.children[i].show();
    }
    $.statusIcon.src = $.EXPANDED;
    $.nodeIcon.src = $.CATEGORYOPEN;
    $.status = "OPEN";
    }

    this.expandOrCollapse = function() {
    if ($.status == "CLOSED") {
    if (currentNode) {
    var ancestor = currentNode.getAncestor(1);
    var myAncestor = $.getAncestor(1);
    if (ancestor && myAncestor && ancestor != myAncestor) {
    ancestor.collapse();
    }
    }
    currentNode = $;
    $.expand();
    } else {
    $.collapse();
    }
    } this.node.onmousedown = function() {
    if (currentNode) {
    currentNode.nodeIcon.src = (currentNode.status == "CLOSED" ? currentNode.CATEGORYCLOSED : currentNode.CATEGORYOPEN);
    }
    }

    this.node.onmouseup = function() {
    if (event.button == 2) {

    }
    }

    this.content.onselectstart = function() {
    return false;
    } this.statusIcon.onclick = this.expandOrCollapse;
    this.nodeIcon.ondblclick = this.expandOrCollapse;
    this.label.onclick = this.expandOrCollapse;

    this.statusIcon.onmouseover = function() {
    this.src = $.status == "CLOSED" ? $.COLLAPSED_HOVER : $.EXPANDED_HOVER;
    }

    this.statusIcon.onmouseout = function() {
    this.src = $.status == "CLOSED" ? $.COLLAPSED : $.EXPANDED;
    }
    }这个事要用来写asp的时候用的  就是给每个节点加权限  怎么加呢?谢谢
      

  2.   

    这位兄台,我现在跟你用的是同一个JS树,现在急着做这个权限的问题,你如果有解决办法,麻烦你帮帮忙,发到我邮箱咯,[email protected],不胜感激呀!!