// Open or close all nodesdTree.prototype.oAll = function(status) {for (var n=0; n<this.aNodes.length; n++) {if (this.aNodes[n]._hc && this.aNodes[n].pid != this.root.id) {this.nodeStatus(status, n, this.aNodes[n]._ls)this.aNodes[n]._io = status;}}if (this.config.useCookies) this.updateCookie();};// Opens the tree to a specific nodedTree.prototype.openTo = function(nId, bSelect, bFirst) {if (!bFirst) {for (var n=0; n<this.aNodes.length; n++) {if (this.aNodes[n].id == nId) {nId=n;break;}}}var cn=this.aNodes[nId];if (cn.pid==this.root.id || !cn._p) return;cn._io = true;cn._is = bSelect;if (this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls);if (this.completed && 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 nodedTree.prototype.closeLevel = function(node) {for (var n=0; n<this.aNodes.length; n++) {if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) {this.nodeStatus(false, n, this.aNodes[n]._ls);this.aNodes[n]._io = false;this.closeAllChildren(this.aNodes[n]);}}}// Closes all children of a nodedTree.prototype.closeAllChildren = function(node) {for (var n=0; n<this.aNodes.length; n++) {if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) {if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls);this.aNodes[n]._io = false;this.closeAllChildren(this.aNodes[n]);}}}// Change the status of a node(open or closed)dTree.prototype.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.aNodes[id].iconOpen : this.aNodes[id].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 cookiedTree.prototype.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 cookiedTree.prototype.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 cookiedTree.prototype.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.substring(posValue));}return (cookieValue);};// [Cookie] Returns ids of open nodes as a stringdTree.prototype.updateCookie = function() {var str = '';for (var n=0; n<this.aNodes.length; n++) {if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) {if (str) str += '.';str += this.aNodes[n].id;}}this.setCookie('co' + this.obj, str);};// [Cookie] Checks if a node id is in a cookiedTree.prototype.isOpen = function(id) {var aOpen = this.getCookie('co' + this.obj).split('.');for (var n=0; n<aOpen.length; n++)if (aOpen[n] == id) return true;return false;};// If Push and pop is not implemented by the browserif (!Array.prototype.push) {Array.prototype.push = function array_push() {for(var i=0;i<arguments.length;i++)this[this.length]=arguments[i];return this.length;}};if (!Array.prototype.pop) {Array.prototype.pop = function array_pop() {lastElement = this[this.length-1];this.length = Math.max(this.length-1,0);return lastElement;}};
</script>
<style>
<--
.dtree {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 11px;
color: #666;
white-space: nowrap;
}
.dtree img {
border: 0px;
vertical-align: middle;
}
.dtree a {
color: #333;
text-decoration: none;
}
.dtree a.node, .dtree a.nodeSel {
white-space: nowrap;
padding: 1px 2px 1px 2px;
}
.dtree a.node:hover, .dtree a.nodeSel:hover {
color: #333;
text-decoration: underline;
}
.dtree a.nodeSel {
background-color: #c0d2ec;
}
.dtree .clip {
overflow: hidden;
}
-->
</style>
</head><body><h1>无限级可刷新Js树型菜单</h1><h2>Example</h2><div class="dtree"><p><a href="javascript: d.openAll();">展开所有</a> | <a href="javascript: d.closeAll();">收起所有</a></p><script type="text/javascript">
<!--d = new dTree('d');d.add(0,-1,'My example tree');
d.add(1,0,'Node A','http://js.bhcode.net');d.add(2,1,'Node AB','http://js.bhcode.net');
d.add(2,0,'Node B','http://js.bhcode.net');
d.add(3,0,'Node C','http://js.bhcode.net');
d.add(4,0,'Node D','http://js.bhcode.net');
d.add(5,0,'Node E','http://js.bhcode.net');
d.add(6,0,'Node F','http://js.bhcode.net');
d.add(7,0,'Node G','http://js.bhcode.net');
d.add(8,0,'Node H','http://js.bhcode.net');
d.add(10,1,'Node AA','http://js.bhcode.net');
d.add(11,1,'Node AAA','http://js.bhcode.net');
d.add(12,1,'Node AAAA','http://js.bhcode.net');
d.add(13,1,'Node AAAAA','http://js.bhcode.net');
d.add(10,2,'Node B','http://js.bhcode.net');
d.add(11,2,'Node BB','http://js.bhcode.net');d.add(12,2,'Node BBB','http://js.bhcode.net');
d.add(10,3,'Node a','http://js.bhcode.net');
d.add(10,4,'Node 1.5','http://js.bhcode.net');
d.add(10,5,'Node g','http://js.bhcode.net');d.add(10,6,'Node 6','http://js.bhcode.net');
d.add(10,7,'Node 1.6','http://js.bhcode.net');
d.add(10,8,'Node v','http://js.bhcode.net');
d.add(9,0,'My Pictures','http://js.bhcode.net','Pictures I\'ve taken over the years','','','imgfolder.gif');
d.add(10,9,'The trip to Iceland','http://js.bhcode.net','Pictures of Gullfoss and Geysir');
d.add(11,9,'Mom\'s birthday','http://js.bhcode.net');
d.add(12,0,'Recycle Bin','http://js.bhcode.net','','','trash.gif');
</script>
<style>
<--
.dtree {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 11px;
color: #666;
white-space: nowrap;
}
.dtree img {
border: 0px;
vertical-align: middle;
}
.dtree a {
color: #333;
text-decoration: none;
}
.dtree a.node, .dtree a.nodeSel {
white-space: nowrap;
padding: 1px 2px 1px 2px;
}
.dtree a.node:hover, .dtree a.nodeSel:hover {
color: #333;
text-decoration: underline;
}
.dtree a.nodeSel {
background-color: #c0d2ec;
}
.dtree .clip {
overflow: hidden;
}
-->
</style>
</head><body><h1>无限级可刷新Js树型菜单</h1><h2>Example</h2><div class="dtree"><p><a href="javascript: d.openAll();">展开所有</a> | <a href="javascript: d.closeAll();">收起所有</a></p><script type="text/javascript">
<!--d = new dTree('d');d.add(0,-1,'My example tree');
d.add(1,0,'Node A','http://js.bhcode.net');d.add(2,1,'Node AB','http://js.bhcode.net');
d.add(2,0,'Node B','http://js.bhcode.net');
d.add(3,0,'Node C','http://js.bhcode.net');
d.add(4,0,'Node D','http://js.bhcode.net');
d.add(5,0,'Node E','http://js.bhcode.net');
d.add(6,0,'Node F','http://js.bhcode.net');
d.add(7,0,'Node G','http://js.bhcode.net');
d.add(8,0,'Node H','http://js.bhcode.net');
d.add(10,1,'Node AA','http://js.bhcode.net');
d.add(11,1,'Node AAA','http://js.bhcode.net');
d.add(12,1,'Node AAAA','http://js.bhcode.net');
d.add(13,1,'Node AAAAA','http://js.bhcode.net');
d.add(10,2,'Node B','http://js.bhcode.net');
d.add(11,2,'Node BB','http://js.bhcode.net');d.add(12,2,'Node BBB','http://js.bhcode.net');
d.add(10,3,'Node a','http://js.bhcode.net');
d.add(10,4,'Node 1.5','http://js.bhcode.net');
d.add(10,5,'Node g','http://js.bhcode.net');d.add(10,6,'Node 6','http://js.bhcode.net');
d.add(10,7,'Node 1.6','http://js.bhcode.net');
d.add(10,8,'Node v','http://js.bhcode.net');
d.add(9,0,'My Pictures','http://js.bhcode.net','Pictures I\'ve taken over the years','','','imgfolder.gif');
d.add(10,9,'The trip to Iceland','http://js.bhcode.net','Pictures of Gullfoss and Geysir');
d.add(11,9,'Mom\'s birthday','http://js.bhcode.net');
d.add(12,0,'Recycle Bin','http://js.bhcode.net','','','trash.gif');
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货