




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
JS树形菜单控件2009-03-02 19:45这个是在阿里西西网站找到的代码,很不错的,外国人写的:引用方法如下: dtree= new dTree(dtree); dtree.add(0,-1,刷新数据,javascript:Set_Item_Page(); /(根节点,子节点,节点名称,节点链接) document.write(dtree); JS文件代码如下:/*-| dTree 2.05 | /javascript/tree/ |-| Copyright (c) 2002-2003 Geir Landr? | | This script can be used freely as long as all | copyright messages are intact. | | Updated: 17.04.2003 |-*/ Node objectfunction Node(id, pid, name, url, title, target, icon, iconOpen, open) this.id = id;this.pid = pid; = name;this.url = url;this.title = title;this.target = target;this.icon = icon;this.iconOpen = iconOpen;this._io = open | false;this._is = false;this._ls = false;this._hc = false;this._ai = 0;this._p;/ Tree objectfunction dTree(objName) this.config = target : null, folderLinks : true, useSelection : true, useCookies : true, useLines : true, useIcons : true, useStatusText : false, closeSameLevel : false, inOrder : falsethis.icon = root : img/base.gif, folder : img/folder.gif, folderOpen : img/folderopen.gif, node : img/page.gif, empty : img/empty.gif, line : img/line.gif, join : img/join.gif, joinBottom : img/joinbottom.gif, plus : img/plus.gif, plusBottom : img/plusbottom.gif, minus : img/minus.gif, minusBottom : img/minusbottom.gif, nlPlus : img/nolines_plus.gif, nlMinus : img/nolines_minus.gif;this.obj = objName;this.aNodes = ;this.aIndent = ;this.root = new Node(-1);this.selectedNode = null;this.selectedFound = false;pleted = false;/ Adds a new node to the node arraydTtotype.add = function(id, pid, name, url, title, target, icon, iconOpen, open) this.aNodesthis.aNodes.length = new Node(id, pid, name, url, title, target, icon, iconOpen, open);/ Open/close all nodesdTtotype.openAll = function() this.oAll(true);dTtotype.closeAll = function() this.oAll(false);/ Outputs the tree to the pagedTtotype.toString = function() var str = n;if (document.getElementById) if (this.config.useCookies) this.selectedNode = this.getSelected(); str += this.addNode(this.root); else str += Browser not supported.;str += ;if (!this.selectedFound) this.selectedNode = null;pleted = true;return str;/ Creates the tree structuredTtotype.addNode = function(pNode) var str = ;var n=0;if (this.config.inOrder) n = pNode._ai;for (n; nthis.aNodes.length; n+) if (this.aNodesn.pid = pNode.id) var cn = this.aNodesn; cn._p = pNode; cn._ai = n; this.setCS(cn); if (!cn.target & this.config.target) cn.target = this.config.target; if (cn._hc & !cn._io & this.config.useCookies) cn._io = this.isOpen(cn.id); if (!this.config.folderLinks & cn._hc) cn.url = null; if (this.config.useSelection & cn.id = this.selectedNode & !this.selectedFound) cn._is = true; this.selectedNode = n; this.selectedFound = true; str += this.node(cn, n); if (cn._ls) break; return str;/ Creates the node icon, url and textdTtotype.node = function(node, nodeId) var str = + this.indent(node, nodeId);if (this.config.useIcons) if (!node.icon) node.icon = (this.root.id = node.pid) ? this.icon.root : (node._hc) ? this.icon.folder : this.icon.node); if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node; if (this.root.id = node.pid) node.icon = this.icon.root; node.iconOpen = this.icon.root; str += ;if (node.url) str += ;else if (!this.config.folderLinks | !node.url) & node._hc & node.pid != this.root.id) str += ;str += ;if (node.url | (!this.config.folderLinks | !node.url) & node._hc) str += ;str += ;if (node._hc) str += ; str += this.addNode(node); str += ;this.aIndent.pop();return str;/ Adds the empty and line iconsdTtotype.indent = function(node, nodeId) var str = ;if (this.root.id != node.pid) for (var n=0; nthis.aIndent.length; n+) str += ; (node._ls) ? this.aIndent.push(0) : this.aIndent.push(1); if (node._hc) str += ; else str += ;return str;/ Checks if a node has any children and if it is the last siblingdTtotype.setCS = function(node) var lastId;for (var n=0; nthis.aNodes.length; n+) if (this.aNodesn.pid = node.id) node._hc = true; if (this.aNodesn.pid = node.pid) lastId = this.aNodesn.id;if (lastId=node.id) node._ls = true;/ Returns the selected nodedTtotype.getSelected = function() var sn = this.getCookie(cs + this.obj);return (sn) ? sn : null;/ Highlights the selected nodedTtotype.s = function(id) if (!this.config.useSelection) return;var cn = this.aNodesid;if (cn._hc & !this.config.folderLinks) return;if (this.selectedNode != id) if (this.selectedNode | this.selectedNode=0) eOld = document.getElementById(s + this.obj + this.selectedNode); eOld.className = node; eNew = document.getElementById(s + this.obj + id); eNew.className = nodeSel; this.selectedNode = id; if (this.config.useCookies) this.setCookie(cs + this.obj, cn.id);/ Toggle Open or closedTtotype.o = function(id) var cn = this.aNodesid;this.nodeStatus(!cn._io, id, cn._ls);cn._io = !cn._io;if (this.config.closeSameLevel) this.closeLevel(cn);if (this.config.useCookies) this.updateCookie();/ Open or close all nodesdTtotype.oAll = function(status) for (var n=0; nthis.aNodes.length; n+) if (this.aNodesn._hc & this.aNodesn.pid != this.root.id) this.nodeStatus(status, n, this.aNodesn._ls) this.aNodesn._io = status; if (this.config.useCookies) this.updateCookie();/ Opens the tree to a specific nodedTtotype.openTo = function(nId, bSelect, bFirst) if (!bFirst) for (var n=0; nthis.aNodes.length; n+) if (this.aNodesn.id = nId) nId=n; break; var cn=this.aNodesnId;if (cn.pid=this.root.id | !cn._p) return;cn._io = true;cn._is = bSelect;if (pleted & cn._hc) this.nodeStatus(true, cn._ai, cn._ls);if (pleted & bSelect) this.s(cn._ai);else if (bSelect) this._sn=cn._ai;this.openTo(cn._p._ai, false, true);/ Closes all nodes on the same level as certain nodedTtotype.closeLevel = function(node) for (var n=0; nthis.aNodes.length; n+) if (this.aNodesn.pid = node.pid & this.aNodesn.id != node.id & this.aNodesn._hc) this.nodeStatus(false, n, this.aNodesn._ls); this.aNodesn._io = false; this.closeAllChildren(this.aNodesn); / Closes all children of a nodedTtotype.closeAllChildren = function(node) for (var n=0; nthis.aNodes.length; n+) if (this.aNodesn.pid = node.id & this.aNodesn._hc) if (this.aNodesn._io) this.nodeStatus(false, n, this.aNodesn._ls); this.aNodesn._io = false; this.closeAllChildren(this.aNodesn); / Change the status of a node(open or closed)dTtotype.nodeStatus = function(status, id, bottom) eDiv = document.getElementById(d + this.obj + id);eJoin = document.getElementById(j + this.obj + id);if (this.config.useIcons) eIcon = document.getElementById(i + this.obj + id); eIcon.src = (status) ? this.aNodesid.iconOpen : this.aNodesid.icon;eJoin.src = (this.config.useLines)?(status)?(bottom)?this.icon.minusBottom:this.icon.minus):(bottom)?this.icon.plusBottom:this.icon.plus):(status)?this.icon.nlMinus:this.icon.nlPlus);eDiv.style.display = (status) ? block: none;/ Cookie Clears a cookiedTtotype.clearCookie = function() var now = new Date();var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);this.setCookie(co+this.obj, cookieValue, yesterday);this.setCookie(cs+this.obj, cookieValue, yesterday);/ Cookie Sets value in a cookiedTtotype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) document.cookie = escape(cookieName) + = + escape(cookieValue) + (expires ? ; expires= + expires.toGMTString() : ) + (path ? ; path= + path : ) + (domain ? ; domain= + domain : ) + (secure ? ; secure : );/ Cookie Gets a value from a cookiedTtotype.getCookie = function(cookieName) var cookieValue = ;var posName = document.cookie.indexOf(escape(cookieName) + =);if (posName != -1) var posValue = posName + (escape(cookieName) + =).length; var endPos = document.cookie.indexOf(;, posValue); if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos); else cookieValue = unescape(document.cookie.subs
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 低温保存对生物样本的影响研究
- 彩铅公鸡课件
- 硬笔规范字知识培训课件
- 2025广东广州市中山大学孙逸仙纪念医院康复医学科医教研岗位和医技岗位招聘2人模拟试卷及参考答案详解一套
- 申祥人体知识培训班课件
- 25秋人教版六年级英语上册Unit 6 How do you feel第1课时教案(练习无答案)
- 2025年嘉兴市南湖区卫生健康系统公开招聘事业单位工作人员12人考前自测高频考点模拟试题及答案详解(历年真题)
- 禅城教师笔试题目及答案
- 综合教育培训考试题及答案
- 2025河南驻马店市正阳县县管国有企业招聘20人(第二批)模拟试卷及答案详解(考点梳理)
- 2025年高中语文必修上册第二单元大单元教学设计
- 2025年高考成人政治试题及答案
- 2025年护理质控标准题库及答案
- 2025年农作物植保员岗位技术基础知识考试题库附含答案
- 2025年长宁储备人才真题及答案
- 光子嫩肤课件讲解
- 人力资源中薪酬管理案例分析题及答案
- 采购业务审计培训
- 2025-2026学年冀美版(2024)小学美术二年级上册(全册)教学设计(附目录P284)
- 服装色彩构成课件
- 化工仪表检修与维护课件
评论
0/150
提交评论