前言:
該例子就是個架構導航 , 左邊包含dtree的架構,點擊上面的節點右邊架構顯示
說明步驟:
1. 首先獲得dtree http://www.destroydrop.com/javascripts/tree/
2. 使用dtree
2.1 匯入dtree.css dtree.js
<link rel="StyleSheet" href="dtree.css" type="text/css"/> <script type="text/JavaScript" src="dtree.js"></script>
3. 關鍵代碼
3.1 大的架構代碼:
<frameset rows="20%,60%,20%"> <frame src="/hr/SystemManager/top.html"> <frameset cols="20%,80%"> <frame src="/hr/SystemManager/left.html" name="leftFrame" > <frame src="/hr/SystemManager/right.html" name="rightFrame" > </frameset> <frame src="/hr/SystemManager/foot.html"> </frameset>
3.1 dtree的代碼
<script type="text/javascript"> d = new dTree('d'); d.add(0,-1,'My example tree'); d.add(1,0,'Node 1','top.html'); d.add(2,0,'Node 2','top.html'); d.add(3,1,'Node 1.1','example01.html'); d.add(4,0,'Node 3','example01.html'); //d.add(5,3,'Node 1.1.1','top.html','top',' ','img/imgfloder.gif'); d.add(5,4,'1','/hr/failure.jsp','','parent.rightFrame'); //在mainFrame架構內顯 d.add(5,3,'點擊我','javascript:junploaction()',"",''); document.write(d);</script><script> function junploaction() { parent.rightFrame.location="left.html"; }</script> 更詳細的請看dtree.zip中的資料 希望對大家有所有小協助
圖片示範 :
點擊之後的圖片
dtree 遞迴思考:
dTree.prototype.selectCheckbox=function(nodeId){ var flag = 0; var temp ; var cs = document.getElementById("c"+this.obj+nodeId).checked; var node = this.aNodes[nodeId]; var len =this.aNodes.length; var same = []; for (n=0; n<len; n++) {if(node.pid==this.aNodes[n].pid){same[same.length] = n;} if ((this.aNodes[n].pid == node.id)) { document.getElementById("c"+this.obj+n).checked=cs;flag = 1;this.selectCheckbox(n); } } if(flag==0){ temp = n;//尋找同級節點//alert(same);for(j=0;j<same.length;j++){ document.getElementById("c"+this.obj+(same[j])).checked=true;} //alert("終止"+this.aNodes[nodeId].name); }