找回密码
 注册
广告投放 虚位以待【阿里云】2核2G云新老同享 99元/年,续费同价做网站就用糖果主机-sugarhosts.comJtti.com-新加坡服务器,美国服务器,香港服务器
查看: 745|回复: 4

[转]js练习“树”,读取xml数据(无层次,结构简单),兼容ie&mf

[复制链接]
发表于 2005 年 12 月 19 日 19:44:13 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
最近看到大家都练习写树,偶也学习学习写了一个,大家多多批评,我好进步,呵呵
不过我看了一些树的xml文档都是在xml中就已经有了树的结构,所以我写了一个xml文档不用分层,来生成树的,不过要给每个节点定义编号和父编号

写得有点糙,大家不要笑话,以后逐渐学习在改进

演示地址: www.lapuasi.com/javascript/xmltree

使用方法:
var tree = new xmlTree('tree'); //生成对象
tree.mode = 1; //设置初始模式,默认全部关闭。0全部关闭,1全部展开
tree.createTree(); //输出树

Javascript代码:
  1. /*
  2. xmlTree v1.1
  3. =================================
  4. Infomation
  5. ----------------------
  6. Author   : Lapuasi
  7. E-Mail   : [email]lapuasi@gmail.com[/email]
  8. WebSite  : [url]http://www.lapuasi.com/javascript[/url]
  9. DateTime : 2005-12-14
  10. Example
  11. ----------------------
  12. var tree = new xmlTree('tree'); //生成对象
  13. tree.mode = 1; //设置初始模式,默认全部关闭。0全部关闭,1全部展开
  14. tree.createTree(); //输出树
  15. for Internet Explorer, Mozilla Firefox
  16. */
  17. function xmlTree(name) {
  18.    this.name         = name;                   //实例名称
  19.    this.xmlFile      = 'xmltree.xml';          //默认xml文件
  20.    this.iconPath     = 'images/'               //默认图标路径
  21.    this.iconFolder   = 'tree_icon_folder.gif'; //默认文件夹图标
  22.    this.iconFile     = 'tree_icon_file.gif';   //默认文件图标
  23.    this.iconOpen     = 'tree_arrow_open.gif';  //默认箭头展开图标
  24.    this.iconOver     = 'tree_arrow_over.gif';  //默认箭头活动图标
  25.    this.iconClose    = 'tree_arrow_close.gif'; //默认箭头关闭图标
  26.    this.mode         = 0;                      //初始模式,默认全部关闭。0全部关闭,1全部展开
  27.    this.html         = '';                     //最终输出html代码
  28.    this.prevTip      = null;                   //上一次被显示的tip的时间编号 (内部使用)
  29.    this.prevSelected = null;                   //上一次被选中的节点的自动编号 (内部使用)
  30. }
  31. xmlTree.prototype.createXMLDOM = function() { //生成XMLDOM对象
  32.    var xmldom;
  33.    if (window.ActiveXObject){
  34.        var xmldom = new ActiveXObject("Microsoft.XMLDOM");
  35.    } else {
  36.        if (document.implementation && document.implementation.createDocument) {
  37.            var xmldom = document.implementation.createDocument("","doc",null);
  38.        }
  39.    }
  40.    xmldom.async = false;
  41.    xmldom.resolveExternals = false;
  42.    xmldom.validateOnParse = false;
  43.    xmldom.preserveWhiteSpace = true;
  44.    return xmldom;
  45. }
  46. xmlTree.prototype.createTree = function() { //生成并打印
  47.    var xmldom = this.createXMLDOM();
  48.    document.write('<div id="tree">Loading...<\/div>'); // 树所用层
  49.    document.write('<div id="treeTip"><\/div>'); //提示所用层
  50.    document.getElementById('treeTip').style.visibility = 'visible';
  51.    document.getElementById('treeTip').style.display = 'none';
  52.    if (xmldom.load(this.xmlFile)) {
  53.        this.createNodes(xmldom);
  54.    } else {
  55.        this.html = 'Load XML Error';
  56.    }
  57.    document.getElementById('tree').innerHTML = this.html;
  58.    return;
  59. }
  60. xmlTree.prototype.getFirstChildData = function(obj, name) { //取得指定名称节点的第一个子节点的数据
  61.    var result = '';
  62.    if (typeof(obj) == 'object' && name != null && name != '') {
  63.        var node = obj.getElementsByTagName(name);
  64.        if (node != null && node.length > 0) {
  65.            result = node[0].firstChild.data;
  66.        }
  67.    }
  68.    return result;
  69. }
  70. xmlTree.prototype.checkChildNodes = function(obj, id) { //检测是否有分支
  71.    var result = false;
  72.    var nodes = obj.getElementsByTagName('node');
  73.    if (nodes != null && nodes.length > 0) {
  74.        var pid;
  75.        for (var i = 0; i < nodes.length; i++) {
  76.            pid = parseInt(nodes[i].getAttribute('parentid'));
  77.            if (isNaN(pid)) pid = 0;
  78.            if (!isNaN(pid) && pid == id) {
  79.                result = true;
  80.                break;
  81.            }
  82.        }
  83.    }
  84.    return result;
  85. }
  86. xmlTree.prototype.createNodes = function(obj, id) { //生成指定编号节点的树
  87.    if (typeof(id) == 'undefined' || isNaN(parseInt(id))) id = 0;
  88.    var nodes = obj.getElementsByTagName('node');
  89.    if (nodes != null && nodes.length > 0) {
  90.        var modeClass, modeSrc, iconClass, iconSrc;
  91.        var nid, npid, nname, nicon, nlink, nexplain, hasChildNodes;
  92.        
  93.        //判断模式类型,并应用样式
  94.        modeClass = 'close';
  95.        modeSrc = this.iconPath + this.iconClose;
  96.        if (this.mode == 1) {
  97.            modeSrc = this.iconPath + this.iconOpen;
  98.            modeClass = 'open';
  99.        }
  100.        if (parseInt(id) == 0) modeClass = 'open';
  101.        this.html += '<ul id="tree_' + id + '_c" class="' + modeClass + '">';
  102.        for (var i = 0; i < nodes.length; i++) {
  103.            npid = parseInt(nodes[i].getAttribute('parentid'));
  104.            if (isNaN(npid)) npid = 0;
  105.            if (npid == id) {
  106.                //初始化
  107.                modeClass = 'close'; iconClass = 'icon-file'; iconSrc = this.iconPath + this.iconFile;
  108.                //取得节点编号并检测
  109.                nid = parseInt(nodes[i].getAttribute('id'));
  110.                if (isNaN(nid)) break;
  111.                this.html += '<li id="tree_' + nid + '"><span onclick="' + this.name + '.action(this,event);" onmouseover="' + this.name + '.action(this,event);" onmouseout="' + this.name + '.action(this,event);">';
  112.                
  113.                //取得节点自定义图标
  114.                //判断是否含有子节点,并确定箭头和图标的图片及样式
  115.                nicon = this.getFirstChildData(nodes[i], 'icon');
  116.                hasChildNodes = this.checkChildNodes(obj, nid);
  117.                if (hasChildNodes) {
  118.                    iconClass = '';
  119.                    iconSrc = this.iconPath + this.iconFolder;
  120.                    this.html += '<img id="tree_' + nid + '_a" src="' + modeSrc + '" class="arrow" \/>'; //箭头
  121.                }
  122.                if (nicon != '') iconSrc = nicon;
  123.                this.html += '<img id="tree_' + nid + '_i" src="' + iconSrc + '" class="' + iconClass + '" \/>'; //图标
  124.                //取得节点名称,连接,说明
  125.                nname = this.getFirstChildData(nodes[i], 'name');
  126.                nlink = this.getFirstChildData(nodes[i], 'link');
  127.                nexplain = this.getFirstChildData(nodes[i], 'explain');
  128.                if (nexplain != '') {
  129.                    nexplain = '\'' + nexplain + '\'';
  130.                    nexplain = 'onmouseover="' + this.name + '.treeTips(' + nexplain + ');window.status = \'\';return true;" onmouseout="' + this.name + '.treeTips();"'
  131.                }
  132.                this.html += '<a id="tree_' + nid + '_l" href="#" onclick="' + this.name + '.action(this,event);" ' + nexplain + '>' + nname + '<\/a><\/span>';
  133.                //obj.documentElement.removeChild(nodes[i]);
  134.                if (hasChildNodes) this.createNodes(obj, nid); //迭代子节点
  135.                this.html += '<\/li>';
  136.            }
  137.        }
  138.        this.html += '<\/ul>';
  139.    }
  140.    return;
  141. }
  142. xmlTree.prototype.action = function(obj, e) { //节点操作
  143.    e = e ? e : (window.event ? window.event : null); //获取操作类型
  144.    e = e.type;
  145.    if (obj.tagName == 'A') {
  146.        try { this.prevSelected.className = '';}
  147.        catch(e) {}
  148.        this.prevSelected = obj;
  149.        obj.className = 'selected';
  150.    }
  151.    if (obj.tagName == 'SPAN') {
  152.        var arrow = obj.firstChild; //取得箭头对象
  153.        var borther = obj;
  154.        while (borther.tagName != 'UL') { //取得分支对象
  155.            borther = borther.nextSibling;
  156.            if (borther == null) break;
  157.        }
  158.        if (borther != null) {
  159.            switch (e) { //检测操作类型并执行相应代码
  160.                case 'click':
  161.                    if (borther.className == 'open') {
  162.                        borther.className = 'close';
  163.                        arrow.src = this.iconPath + this.iconClose;
  164.                    } else {
  165.                        borther.className = 'open';
  166.                        arrow.src = this.iconPath + this.iconOpen;
  167.                    }
  168.                    break;
  169.                case 'mouseover':
  170.                    if (arrow.tagName == 'IMG' && borther.className == 'close') {
  171.                        arrow.src = this.iconPath + this.iconOver;
  172.                    }
  173.                    break;
  174.                case 'mouseout':
  175.                    if (arrow.tagName == 'IMG' && borther.className == 'close') {
  176.                        arrow.src = this.iconPath + this.iconClose;
  177.                    }
  178.                    break;
  179.            }
  180.        }
  181.    }
  182.    return;
  183. }
  184. xmlTree.prototype.treeTips = function(msg) { //提示栏
  185.    if (this.prevTip != null) clearTimeout(this.prevTip);
  186.    var obj = document.getElementById('treeTip');
  187.    if (obj != null) {
  188.        if (this.treeTips.arguments.length < 1) { // hide
  189.            obj.style.display = 'none';
  190.        } else { // show
  191.            obj.innerHTML = msg;
  192.            this.prevTip = setTimeout('document.getElementById("treeTip").style.display = "block"',300);
  193.            document.onmousemove = this.moveToMouseLoc;
  194.        }
  195.    }
  196.    return;
  197. }
  198. xmlTree.prototype.moveToMouseLoc = function(e) { //移动到鼠标所在位置
  199.    var obj = document.getElementById('treeTip');
  200.    if (obj != null) {
  201.        var offsetX = -10, offsetY = 20;
  202.        var x = 0, y = 0;
  203.        if (window.event) {
  204.            x = event.x + document.body.scrollLeft;
  205.            y = event.y + document.body.scrollTop;
  206.        } else {
  207.            x = e.pageX;
  208.            y = e.pageY;
  209.        }
  210.        obj.style.left = x + offsetX + 'px';
  211.        obj.style.top = y + offsetY + 'px';
  212.    }
  213.    return;
  214. }
复制代码

xml 数据:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. CODE BY Lapuasi.com [2005-12-14]
  4. Explain:
  5. ===================================================
  6. node 为树的一个节点,具有以下属性和内容
  7.    属性
  8.        id: 编号,如果不唯一,只取第一个,其余被忽略 (必须)
  9.        parentid: 父编号,没有则为父节点 (可选)
  10.    内容
  11.        name: 名称 (必须)
  12.        link: 连接 (可选)
  13.        icon: 图标 (可选)
  14.        explain: 说明 (可选)
  15. -->
  16. <root>
  17.    <node id="1">
  18.        <name>我的电脑</name>
  19.        <icon>images/tree_icon_computer.gif</icon>
  20.        <explain>显示连接到此计算机的驱动器和硬件</explain>
  21.    </node>
  22.    <node id="2" parentid="1">
  23.        <name>硬盘驱动器 (C:)</name>
  24.        <icon>images/tree_icon_driver.gif</icon>
  25.    </node>
  26.    <node id="3">
  27.        <name>网上邻居</name>
  28.        <icon>images/tree_icon_net.gif</icon>
  29.        <explain>显示到网站,网络计算机和FTP站点的快捷方式</explain>
  30.    </node>
  31.    <node id="4" parentid="1">
  32.        <name>硬盘驱动器 (D:)</name>
  33.        <icon>images/tree_icon_driver.gif</icon>
  34.    </node>
  35.    <node id="5" parentid="2">
  36.        <name>Windows</name>
  37.    </node>
  38.    <node id="6" parentid="3">
  39.        <name>menu6</name>
  40.    </node>
  41.    <node id="7" parentid="3">
  42.        <name>menu7</name>
  43.    </node>
  44.    <node id="8" parentid="3">
  45.        <name>menu8</name>
  46.    </node>
  47.    <node id="9" parentid="7">
  48.        <name>menu9</name>
  49.    </node>
  50.    <node id="10">
  51.        <name>回收站</name>
  52.        <icon>images/tree_icon_recycler.gif</icon>
  53.        <explain>包含您已经删除的文件和文件夹</explain>
  54.    </node>
  55.    <node id="11" parentid="5">
  56.        <name>system32</name>
  57.    </node>
  58.    <node id="12" parentid="11">
  59.        <name>system.dll</name>
  60.    </node>
  61.    <node id="13" parentid="7">
  62.        <name>menu13</name>
  63.    </node>
  64.    <node id="14" parentid="1">
  65.        <name>DVD 驱动器</name>
  66.        <icon>images/tree_icon_cdrom.gif</icon>
  67.    </node>
  68. </root>
复制代码
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
发表于 2005 年 12 月 20 日 00:42:39 | 显示全部楼层
【腾讯云】2核2G云服务器新老同享 99元/年,续费同价
记得以前有个asp.net的树很牛X,据说能几千层
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 12 月 20 日 13:51:13 | 显示全部楼层
OMG.......................
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 12 月 20 日 15:19:30 | 显示全部楼层
我想要能解析RSS的
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

 楼主| 发表于 2005 年 12 月 19 日 19:44:13 | 显示全部楼层

[转]js练习“树”,读取xml数据(无层次,结构简单),兼容ie&mf

最近看到大家都练习写树,偶也学习学习写了一个,大家多多批评,我好进步,呵呵
不过我看了一些树的xml文档都是在xml中就已经有了树的结构,所以我写了一个xml文档不用分层,来生成树的,不过要给每个节点定义编号和父编号

写得有点糙,大家不要笑话,以后逐渐学习在改进

演示地址: www.lapuasi.com/javascript/xmltree

使用方法:
var tree = new xmlTree('tree'); //生成对象
tree.mode = 1; //设置初始模式,默认全部关闭。0全部关闭,1全部展开
tree.createTree(); //输出树

Javascript代码:
  1. /*
  2. xmlTree v1.1
  3. =================================
  4. Infomation
  5. ----------------------
  6. Author   : Lapuasi
  7. E-Mail   : [email]lapuasi@gmail.com[/email]
  8. WebSite  : [url]http://www.lapuasi.com/javascript[/url]
  9. DateTime : 2005-12-14
  10. Example
  11. ----------------------
  12. var tree = new xmlTree('tree'); //生成对象
  13. tree.mode = 1; //设置初始模式,默认全部关闭。0全部关闭,1全部展开
  14. tree.createTree(); //输出树
  15. for Internet Explorer, Mozilla Firefox
  16. */
  17. function xmlTree(name) {
  18.    this.name         = name;                   //实例名称
  19.    this.xmlFile      = 'xmltree.xml';          //默认xml文件
  20.    this.iconPath     = 'images/'               //默认图标路径
  21.    this.iconFolder   = 'tree_icon_folder.gif'; //默认文件夹图标
  22.    this.iconFile     = 'tree_icon_file.gif';   //默认文件图标
  23.    this.iconOpen     = 'tree_arrow_open.gif';  //默认箭头展开图标
  24.    this.iconOver     = 'tree_arrow_over.gif';  //默认箭头活动图标
  25.    this.iconClose    = 'tree_arrow_close.gif'; //默认箭头关闭图标
  26.    this.mode         = 0;                      //初始模式,默认全部关闭。0全部关闭,1全部展开
  27.    this.html         = '';                     //最终输出html代码
  28.    this.prevTip      = null;                   //上一次被显示的tip的时间编号 (内部使用)
  29.    this.prevSelected = null;                   //上一次被选中的节点的自动编号 (内部使用)
  30. }
  31. xmlTree.prototype.createXMLDOM = function() { //生成XMLDOM对象
  32.    var xmldom;
  33.    if (window.ActiveXObject){
  34.        var xmldom = new ActiveXObject("Microsoft.XMLDOM");
  35.    } else {
  36.        if (document.implementation && document.implementation.createDocument) {
  37.            var xmldom = document.implementation.createDocument("","doc",null);
  38.        }
  39.    }
  40.    xmldom.async = false;
  41.    xmldom.resolveExternals = false;
  42.    xmldom.validateOnParse = false;
  43.    xmldom.preserveWhiteSpace = true;
  44.    return xmldom;
  45. }
  46. xmlTree.prototype.createTree = function() { //生成并打印
  47.    var xmldom = this.createXMLDOM();
  48.    document.write('<div id="tree">Loading...<\/div>'); // 树所用层
  49.    document.write('<div id="treeTip"><\/div>'); //提示所用层
  50.    document.getElementById('treeTip').style.visibility = 'visible';
  51.    document.getElementById('treeTip').style.display = 'none';
  52.    if (xmldom.load(this.xmlFile)) {
  53.        this.createNodes(xmldom);
  54.    } else {
  55.        this.html = 'Load XML Error';
  56.    }
  57.    document.getElementById('tree').innerHTML = this.html;
  58.    return;
  59. }
  60. xmlTree.prototype.getFirstChildData = function(obj, name) { //取得指定名称节点的第一个子节点的数据
  61.    var result = '';
  62.    if (typeof(obj) == 'object' && name != null && name != '') {
  63.        var node = obj.getElementsByTagName(name);
  64.        if (node != null && node.length > 0) {
  65.            result = node[0].firstChild.data;
  66.        }
  67.    }
  68.    return result;
  69. }
  70. xmlTree.prototype.checkChildNodes = function(obj, id) { //检测是否有分支
  71.    var result = false;
  72.    var nodes = obj.getElementsByTagName('node');
  73.    if (nodes != null && nodes.length > 0) {
  74.        var pid;
  75.        for (var i = 0; i < nodes.length; i++) {
  76.            pid = parseInt(nodes[i].getAttribute('parentid'));
  77.            if (isNaN(pid)) pid = 0;
  78.            if (!isNaN(pid) && pid == id) {
  79.                result = true;
  80.                break;
  81.            }
  82.        }
  83.    }
  84.    return result;
  85. }
  86. xmlTree.prototype.createNodes = function(obj, id) { //生成指定编号节点的树
  87.    if (typeof(id) == 'undefined' || isNaN(parseInt(id))) id = 0;
  88.    var nodes = obj.getElementsByTagName('node');
  89.    if (nodes != null && nodes.length > 0) {
  90.        var modeClass, modeSrc, iconClass, iconSrc;
  91.        var nid, npid, nname, nicon, nlink, nexplain, hasChildNodes;
  92.        
  93.        //判断模式类型,并应用样式
  94.        modeClass = 'close';
  95.        modeSrc = this.iconPath + this.iconClose;
  96.        if (this.mode == 1) {
  97.            modeSrc = this.iconPath + this.iconOpen;
  98.            modeClass = 'open';
  99.        }
  100.        if (parseInt(id) == 0) modeClass = 'open';
  101.        this.html += '<ul id="tree_' + id + '_c" class="' + modeClass + '">';
  102.        for (var i = 0; i < nodes.length; i++) {
  103.            npid = parseInt(nodes[i].getAttribute('parentid'));
  104.            if (isNaN(npid)) npid = 0;
  105.            if (npid == id) {
  106.                //初始化
  107.                modeClass = 'close'; iconClass = 'icon-file'; iconSrc = this.iconPath + this.iconFile;
  108.                //取得节点编号并检测
  109.                nid = parseInt(nodes[i].getAttribute('id'));
  110.                if (isNaN(nid)) break;
  111.                this.html += '<li id="tree_' + nid + '"><span onclick="' + this.name + '.action(this,event);" onmouseover="' + this.name + '.action(this,event);" onmouseout="' + this.name + '.action(this,event);">';
  112.                
  113.                //取得节点自定义图标
  114.                //判断是否含有子节点,并确定箭头和图标的图片及样式
  115.                nicon = this.getFirstChildData(nodes[i], 'icon');
  116.                hasChildNodes = this.checkChildNodes(obj, nid);
  117.                if (hasChildNodes) {
  118.                    iconClass = '';
  119.                    iconSrc = this.iconPath + this.iconFolder;
  120.                    this.html += '<img id="tree_' + nid + '_a" src="' + modeSrc + '" class="arrow" \/>'; //箭头
  121.                }
  122.                if (nicon != '') iconSrc = nicon;
  123.                this.html += '<img id="tree_' + nid + '_i" src="' + iconSrc + '" class="' + iconClass + '" \/>'; //图标
  124.                //取得节点名称,连接,说明
  125.                nname = this.getFirstChildData(nodes[i], 'name');
  126.                nlink = this.getFirstChildData(nodes[i], 'link');
  127.                nexplain = this.getFirstChildData(nodes[i], 'explain');
  128.                if (nexplain != '') {
  129.                    nexplain = '\'' + nexplain + '\'';
  130.                    nexplain = 'onmouseover="' + this.name + '.treeTips(' + nexplain + ');window.status = \'\';return true;" onmouseout="' + this.name + '.treeTips();"'
  131.                }
  132.                this.html += '<a id="tree_' + nid + '_l" href="#" onclick="' + this.name + '.action(this,event);" ' + nexplain + '>' + nname + '<\/a><\/span>';
  133.                //obj.documentElement.removeChild(nodes[i]);
  134.                if (hasChildNodes) this.createNodes(obj, nid); //迭代子节点
  135.                this.html += '<\/li>';
  136.            }
  137.        }
  138.        this.html += '<\/ul>';
  139.    }
  140.    return;
  141. }
  142. xmlTree.prototype.action = function(obj, e) { //节点操作
  143.    e = e ? e : (window.event ? window.event : null); //获取操作类型
  144.    e = e.type;
  145.    if (obj.tagName == 'A') {
  146.        try { this.prevSelected.className = '';}
  147.        catch(e) {}
  148.        this.prevSelected = obj;
  149.        obj.className = 'selected';
  150.    }
  151.    if (obj.tagName == 'SPAN') {
  152.        var arrow = obj.firstChild; //取得箭头对象
  153.        var borther = obj;
  154.        while (borther.tagName != 'UL') { //取得分支对象
  155.            borther = borther.nextSibling;
  156.            if (borther == null) break;
  157.        }
  158.        if (borther != null) {
  159.            switch (e) { //检测操作类型并执行相应代码
  160.                case 'click':
  161.                    if (borther.className == 'open') {
  162.                        borther.className = 'close';
  163.                        arrow.src = this.iconPath + this.iconClose;
  164.                    } else {
  165.                        borther.className = 'open';
  166.                        arrow.src = this.iconPath + this.iconOpen;
  167.                    }
  168.                    break;
  169.                case 'mouseover':
  170.                    if (arrow.tagName == 'IMG' && borther.className == 'close') {
  171.                        arrow.src = this.iconPath + this.iconOver;
  172.                    }
  173.                    break;
  174.                case 'mouseout':
  175.                    if (arrow.tagName == 'IMG' && borther.className == 'close') {
  176.                        arrow.src = this.iconPath + this.iconClose;
  177.                    }
  178.                    break;
  179.            }
  180.        }
  181.    }
  182.    return;
  183. }
  184. xmlTree.prototype.treeTips = function(msg) { //提示栏
  185.    if (this.prevTip != null) clearTimeout(this.prevTip);
  186.    var obj = document.getElementById('treeTip');
  187.    if (obj != null) {
  188.        if (this.treeTips.arguments.length < 1) { // hide
  189.            obj.style.display = 'none';
  190.        } else { // show
  191.            obj.innerHTML = msg;
  192.            this.prevTip = setTimeout('document.getElementById("treeTip").style.display = "block"',300);
  193.            document.onmousemove = this.moveToMouseLoc;
  194.        }
  195.    }
  196.    return;
  197. }
  198. xmlTree.prototype.moveToMouseLoc = function(e) { //移动到鼠标所在位置
  199.    var obj = document.getElementById('treeTip');
  200.    if (obj != null) {
  201.        var offsetX = -10, offsetY = 20;
  202.        var x = 0, y = 0;
  203.        if (window.event) {
  204.            x = event.x + document.body.scrollLeft;
  205.            y = event.y + document.body.scrollTop;
  206.        } else {
  207.            x = e.pageX;
  208.            y = e.pageY;
  209.        }
  210.        obj.style.left = x + offsetX + 'px';
  211.        obj.style.top = y + offsetY + 'px';
  212.    }
  213.    return;
  214. }
复制代码

xml 数据:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. CODE BY Lapuasi.com [2005-12-14]
  4. Explain:
  5. ===================================================
  6. node 为树的一个节点,具有以下属性和内容
  7.    属性
  8.        id: 编号,如果不唯一,只取第一个,其余被忽略 (必须)
  9.        parentid: 父编号,没有则为父节点 (可选)
  10.    内容
  11.        name: 名称 (必须)
  12.        link: 连接 (可选)
  13.        icon: 图标 (可选)
  14.        explain: 说明 (可选)
  15. -->
  16. <root>
  17.    <node id="1">
  18.        <name>我的电脑</name>
  19.        <icon>images/tree_icon_computer.gif</icon>
  20.        <explain>显示连接到此计算机的驱动器和硬件</explain>
  21.    </node>
  22.    <node id="2" parentid="1">
  23.        <name>硬盘驱动器 (C:)</name>
  24.        <icon>images/tree_icon_driver.gif</icon>
  25.    </node>
  26.    <node id="3">
  27.        <name>网上邻居</name>
  28.        <icon>images/tree_icon_net.gif</icon>
  29.        <explain>显示到网站,网络计算机和FTP站点的快捷方式</explain>
  30.    </node>
  31.    <node id="4" parentid="1">
  32.        <name>硬盘驱动器 (D:)</name>
  33.        <icon>images/tree_icon_driver.gif</icon>
  34.    </node>
  35.    <node id="5" parentid="2">
  36.        <name>Windows</name>
  37.    </node>
  38.    <node id="6" parentid="3">
  39.        <name>menu6</name>
  40.    </node>
  41.    <node id="7" parentid="3">
  42.        <name>menu7</name>
  43.    </node>
  44.    <node id="8" parentid="3">
  45.        <name>menu8</name>
  46.    </node>
  47.    <node id="9" parentid="7">
  48.        <name>menu9</name>
  49.    </node>
  50.    <node id="10">
  51.        <name>回收站</name>
  52.        <icon>images/tree_icon_recycler.gif</icon>
  53.        <explain>包含您已经删除的文件和文件夹</explain>
  54.    </node>
  55.    <node id="11" parentid="5">
  56.        <name>system32</name>
  57.    </node>
  58.    <node id="12" parentid="11">
  59.        <name>system.dll</name>
  60.    </node>
  61.    <node id="13" parentid="7">
  62.        <name>menu13</name>
  63.    </node>
  64.    <node id="14" parentid="1">
  65.        <name>DVD 驱动器</name>
  66.        <icon>images/tree_icon_cdrom.gif</icon>
  67.    </node>
  68. </root>
复制代码
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|金光论坛

GMT+8, 2025 年 2 月 1 日 11:56 , Processed in 0.023383 second(s), 24 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表