各位大侠小弟高分求一代码!分数不够可以再加!
求用javascript 与DIV实现的三层或以上的树型目录
[解决办法]
/*****************************
JavaScript Code for CNLTreeMenu
Version: Ver 1.02
Author : CNLei, 枫岩
E-Mail : CNLei.Y.L@gmail.com
MySite : http://www.cnlei.net
Passed : XHtml 1.0, CSS 2.0, IE5.0+, FF1.0+, Opera8.5+
Update : 2006-2-12
*****************************/
function Ob(o){
var o=document.getElementById(o)?document.getElementById(o):o;
return o;
}
function Hd(o) {
Ob(o).style.display= "none ";
}
function Sw(o) {
Ob(o).style.display= " ";
}
function ExCls(o,a,b,n){
var o=Ob(o);
for(i=0;i <n;i++) {o=o.parentNode;}
o.className=o.className==a?b:a;
}
function CNLTreeMenu(id,TagName0) {
this.id=id;
this.TagName0=TagName0== " "? "li ":TagName0;
this.AllNodes = Ob(this.id).getElementsByTagName(TagName0);
this.InitCss = function (ClassName0,ClassName1,ClassName2,ImgUrl) {
this.ClassName0=ClassName0;
this.ClassName1=ClassName1;
this.ClassName2=ClassName2;
this.ImgUrl=ImgUrl || "css/s.gif ";
this.ImgBlankA = " <img src=\ " "+this.ImgUrl+ "\ " class=\ "s\ " onclick=\ "ExCls(this, ' "+ClassName0+ " ', ' "+ClassName1+ " ',1);\ " alt=\ "展开/折叠\ " /> ";
this.ImgBlankB = " <img src=\ " "+this.ImgUrl+ "\ " class=\ "s\ " /> ";
for (i=0;i <this.AllNodes.length;i++ ) {
this.AllNodes[i].className== " "?this.AllNodes[i].className=ClassName1: " ";
this.AllNodes[i].innerHTML=(this.AllNodes[i].className==ClassName2?this.ImgBlankB:this.ImgBlankA)+this.AllNodes[i].innerHTML;
}
}
this.SetNodes = function (n) {
var sClsName=n==0?this.ClassName0:this.ClassName1;
for (i=0;i <this.AllNodes.length;i++ ) {
this.AllNodes[i].className==this.ClassName2? " ":this.AllNodes[i].className=sClsName;
}
}
}
[解决办法]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml " lang= "zh-cn ">
<head>
<title> CNL Tree Menu Ver1.02 - 无限级树形菜单 Written by CNLei, 枫岩 </title>
<meta http-equiv= "content-type " content= "text/html;charset=gb2312 " />
<meta name= "generator " content= "editplus " />
<meta name= "author " content= "CNLei,枫岩,www.cnlei.net " />
<meta name= "keywords " content= "CSS Menu,树形菜单,CNLei " />
<meta name= "description " content= " " />
<!--
**************************************
HTML Code for CNLTreeMenu
Version: Ver 1.02
Author : CNLei, 枫岩
E-Mail : CNLei.Y.L@gmail.com
MySite : http://www.cnlei.net
Passed : XHtml 1.0, CSS 2.0, IE5.0+, FF1.0+, Opera8.5+
Update : 2006-2-12
**************************************
-->
<link type= "text/css " rel= "stylesheet " href= "css/css4cnltreemenu.css " />
<script type= "text/javascript " src= "js/js4cnltreemenu.js "> </script>
</head>
<body>
<p> 实例演示: </p>
<dl>
<dt> CNL Tree Menu <small> Ver1.02 </small> </dt>
<dd> <strong> Author </strong> :CNLei,枫岩 </dd>
<dd> <strong> MySite </strong> : <a href= "http://www.cnlei.net " style= "color:#00f; "> www.cnlei.net </a> , <a href= "http://cnlei.iecn.net " style= "color:#00f; "> cnlei.iecn.net </a> </dd>
<dd> <strong> E-Mail </strong> :cnlei.y.l <span style= "color:#00f "> # </span> gail.com (请将 <span style= "color:#00f "> # </span> 换成 <span style= "color:#00f "> @ </span> ) </dd>
<dd> <strong> Intro </strong> :
<ol>
<li> "CNL Tree Menu "为无限级树形,兼容以下版本的浏览器:IE5.0+, FF1.06+, Opera8.5+ …… </li>
<li> HTML,CSS,JavaScript代码相互分离(即数据,风格,脚本三者分离),可应用于多种场合,易于维护修改;更换树形图标,只需要修改CSS文件. </li>
<li> 通过W3C校验(XHtml1-Strict,CSS1.0). </li>
<li> 最后更新:2006-2-13 </li>
<li> 下载地址: <a href= "http://cnlei.iecn.net/mycode/CNLTreeMenu/CNLTreeMenuVer1.0.2.rar "> 点击下载 </a> </li>
</ol>
</dd>
</dl>
<!--CNLTreeMenu Start:-->
<div class= "CNLTreeMenu " id= "CNLTreeMenu1 ">
<h4> CNL Tree Menu1 </h4>
<p> <a id= "AllOpen_1 " href= "# " onclick= "MyCNLTreeMenu1.SetNodes(0);Hd(this);Sw( 'AllClose_1 '); "> 全部展开 </a> <a id= "AllClose_1 " href= "# " onclick= "MyCNLTreeMenu1.SetNodes(1);Hd(this);Sw( 'AllOpen_1 '); " style= "display:none; "> 全部折叠 </a> </p>
<ul>
<li class= "Opened "> <a href= "http://www.iecn.net "> IECN.Net </a>
<ul>
<li> <a href= "#1 "> 技术区 </a>
<ul>
<li> <a href= "# "> 网页技术 </a>
<ul>
<li class= "Child "> <a href= "# "> JavaScript </a> </li> <!--Child Node-->
<li class= "Child "> <a href= "# "> HTML/XHTML/CSS </a> </li>
<li class= "Child "> <a href= "# "> Ajax </a> </li>
<li class= "Child "> <a href= "# "> 网页制作工具 </a> </li>
<li class= "Child "> <a href= "# "> 设计/图形 </a> </li>
<li class= "Child "> <a href= "# "> Flash/多媒体 </a> </li>
<li class= "Child "> <a href= "# "> VML/Web3D </a> </li>
</ul> </li> <!--Sub Node 3-->
<li> <a href= "# "> Web编程 </a>
<ul>
<li class= "Child "> <a href= "# "> Java </a> </li> <!--Child Node-->
<li class= "Child "> <a href= "# "> .Net </a> </li>
<li class= "Child "> <a href= "# "> ASP/VBScript </a> </li>
<li class= "Child "> <a href= "# "> PHP </a> </li>
<li class= "Child "> <a href= "# "> Perl/Python </a> </li>
<li class= "Child "> <a href= "# "> Web综合/开源 </a> </li>
</ul> </li> <!--Sub Node 3-->
<li> <a href= "# "> 数据库 </a>
<ul>
<li class= "Child "> <a href= "# "> Access/SQLServer </a> </li> <!--Child Node-->
<li class= "Child "> <a href= "# "> MySQL/PostgreSQL </a> </li>
<li class= "Child "> <a href= "# "> Oracle/DB2/Sybase </a> </li>
</ul> </li> <!--Sub Node 3-->
<li> <a href= "# "> 服务器 </a>
<ul>
<li class= "Child "> <a href= "# "> Windows/IIS </a> </li> <!--Child Node-->
<li class= "Child "> <a href= "# "> Unix/Linux/Apache </a> </li>
<li class= "Child "> <a href= "# "> 应用服务器 </a> </li>
</ul> </li> <!--Sub Node 3-->
</ul> </li> <!--Sub Node 2-->
<li> <a href= "#1 "> 二级目录 </a>
<ul>
<li> <a href= "# "> 三级目录 </a>
<ul>
<li> <a href= "# "> 四级目录 </a>
<ul>
<li> <a href= "# "> 五级目录 </a>
<ul>
<li> <a href= "# "> ...... </a>
<ul>
<li> <a href= "# "> 第n级目录 </a>
<ul>
<li class= "Child "> <a href= "# "> 叶结点1 </a> </li> <!--Child Node-->
<li class= "Child "> <a href= "# "> 叶结点2 </a> </li>
<li class= "Child "> <a href= "# "> 叶结点3 </a> </li>
</ul> </li> <!--Sub Node n -->
</ul> </li> <!--Sub Node 6 -->
</ul> </li> <!--Sub Node 5 -->
</ul> </li> <!--Sub Node 4-->
</ul> </li> <!--Sub Node 3-->
</ul> </li> <!--Sub Node 2-->
<li> <a href= "#1 "> 二级目录 </a>
<ul>
<li> <a href= "# "> 三级目录 </a>
<ul>
<li> <a href= "# "> 四级目录 </a>
<ul>
<li> <a href= "# "> 五级目录 </a>
<ul>
<li> <a href= "# "> ...... </a>
<ul>
<li> <a href= "# "> 第n级目录 </a>
<ul>
<li class= "Child "> <a href= "# "> 叶结点1 </a> </li> <!--Child Node-->
<li class= "Child "> <a href= "# "> 叶结点2 </a> </li>
<li class= "Child "> <a href= "# "> 叶结点3 </a> </li>
</ul> </li> <!--Sub Node n -->
</ul> </li> <!--Sub Node 6 -->
</ul> </li> <!--Sub Node 5 -->
</ul> </li> <!--Sub Node 4-->
</ul> </li> <!--Sub Node 3-->
</ul> </li> <!--Sub Node 2-->
</ul> </li> <!--Sub Node 1 -->
</ul>
</div> <!-- CNLTreeMenu -->
<!--CNLTreeMenu1 End!-->
<!--CNLTreeMenu2 Start:-->
<div class= "CNLTreeMenu " id= "CNLTreeMenu2 ">
<h4> CNL Tree Menu2 </h4>
<p> <a id= "AllOpen_2 " href= "# " onclick= "MyCNLTreeMenu2.SetNodes(0);Hd(this);Sw( 'AllClose_2 '); "> 全部展开 </a> <a id= "AllClose_2 " href= "# " onclick= "MyCNLTreeMenu2.SetNodes(1);Hd(this);Sw( 'AllOpen_2 '); " style= "display:none; "> 全部折叠 </a> </p>
<ul>
<li class= "Opened "> <a href= "http://www.iecn.net "> IECN.Net </a>
<ul>
<li> <a href= "#1 "> 技术区 </a>
<ul>
<li> <a href= "# "> 网页技术 </a>
<ul>
<li class= "Child "> <a href= "# "> JavaScript </a> </li> <!--Child Node-->
<li class= "Child "> <a href= "# "> HTML/XHTML/CSS </a> </li>
<li class= "Child "> <a href= "# "> Ajax </a> </li>
<li class= "Child "> <a href= "# "> 网页制作工具 </a> </li>
<li class= "Child "> <a href= "# "> 设计/图形 </a> </li>
<li class= "Child "> <a href= "# "> Flash/多媒体 </a> </li>
<li class= "Child "> <a href= "# "> VML/Web3D </a> </li>
</ul> </li> <!--Sub Node 3-->
<li> <a href= "# "> Web编程 </a>
<ul>
<li class= "Child "> <a href= "# "> Java </a> </li> <!--Child Node-->
<li class= "Child "> <a href= "# "> .Net </a> </li>
<li class= "Child "> <a href= "# "> ASP/VBScript </a> </li>
<li class= "Child "> <a href= "# "> PHP </a> </li>
<li class= "Child "> <a href= "# "> Perl/Python </a> </li>
<li class= "Child "> <a href= "# "> Web综合/开源 </a> </li>
</ul> </li> <!--Sub Node 3-->
<li> <a href= "# "> 数据库 </a>
<ul>
<li class= "Child "> <a href= "# "> Access/SQLServer </a> </li> <!--Child Node-->
<li class= "Child "> <a href= "# "> MySQL/PostgreSQL </a> </li>
<li class= "Child "> <a href= "# "> Oracle/DB2/Sybase </a> </li>
</ul> </li> <!--Sub Node 3-->
<li> <a href= "# "> 服务器 </a>
<ul>
<li class= "Child "> <a href= "# "> Windows/IIS </a> </li> <!--Child Node-->
<li class= "Child "> <a href= "# "> Unix/Linux/Apache </a> </li>
<li class= "Child "> <a href= "# "> 应用服务器 </a> </li>
</ul> </li> <!--Sub Node 3-->
</ul> </li> <!--Sub Node 2-->
[解决办法]
<script language= "JavaScript ">
NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
ver4 = (NS4 || IE4) ? 1 : 0;
if (ver4) {
with (document) {
write( " <STYLE TYPE= "text/css "> ");
if (NS4) {
write( ".parent {position:absolute; visibility:visible} ");
write( ".child {position:absolute; visibility:visible} ");
write( ".regular {position:absolute; visibility:visible} ")
}
else {
write( ".child {display:none} ")
}
write( " </STYLE> ");
}
}
function getIndex(el) {
ind = null;
for (i=0; i <document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.id == el) {
ind = i;
break;
}
}
return ind;
}
function arrange() {
nextY = document.layers[firstInd].pageY +document.layers[firstInd].document.height;
for (i=firstInd+1; i <document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.visibility != "hide ") {
whichEl.pageY = nextY;
nextY += whichEl.document.height;
}
}
}
function initIt(){
if (!ver4) return;
if (NS4) {
for (i=0; i <document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.id.indexOf( "Child ") != -1) whichEl.visibility = "hide ";
}
arrange();
}
else {
divColl = document.all.tags( "DIV ");
for (i=0; i <divColl.length; i++) {
whichEl = divColl(i);
if (whichEl.className == "child ") whichEl.style.display = "none ";
}
}
}
function expandIt(el) {
if (!ver4) return;
if (IE4) {
whichEl = eval(el + "Child ");
if (whichEl.style.display == "none ") {
whichEl.style.display = "block ";
}
else {
whichEl.style.display = "none ";
}
}
else {
whichEl = eval( "document. " + el + "Child ");
if (whichEl.visibility == "hide ") {
whichEl.visibility = "show ";
}
else {
whichEl.visibility = "hide ";
}
arrange();
}
}
onload = initIt;
</script>
</font> </p>
<div id= "KB1Parent " class= "parent "> <a href= "# " onClick= "expandIt( "KB1 "); return false " > <img src= "img/plus.gif " border=0> 文件夹一 </a> </div>
<div id= "KB1Child " class= "child "> <a href= "sample.htm " target= "_blank " > <img src= "img/spacer.gif " border=0 alt= " "> <img src= "img/open.gif " border=0> 页面一 </a> <br>
<a href= "sample.htm " target= "_blank " > <img src= "img/spacer.gif " border=0 alt= " " width= "15 " height= "11 "> <img src= "img/open.gif " border=0> 页面二 </a> <br>
<a href= "sample.htm " target= "_blank " > <img src= "img/spacer.gif " border=0 alt= " " width= "15 " height= "11 "> <img src= "img/open.gif " border=0> 页面三 </a> </div>
<div id= "KB2Parent " class= "parent "> <a href= "# " onClick= "expandIt( "KB2 "); return false " > <img src= "img/plus.gif " border=0> 文件夹二 </a> </div>
<div id= "KB2Child " class= "child "> <a href= "sample.htm " target= "_blank " > <img src= "img/spacer.gif " border=0 alt= " " width= "15 " height= "11 "> <img src= "img/open.gif " border=0> 页面一 </a> <br>
<a href= "sample.htm " target= "_blank " > <img src= "img/spacer.gif " border=0 alt= " "> <img src= "img/open.gif " border=0> 页面二 </a> <br>
<a href= "sample.htm " target= "_blank " > <img src= "img/spacer.gif " border=0 alt= " " width= "15 " height= "11 "> <img src= "img/open.gif " border=0> 页面三 </a> </div>
<div id= "KB3Parent " class= "parent "> <a href= "# " onClick= "expandIt( "KB3 "); return false " > <img src= "img/plus.gif " border=0> 文件夹三 </a> </div>
<div id= "KB3Child " class= "child "> <a href= "sample.htm " target= "_blank " > <img src= "img/spacer.gif " border=0 alt= " "> <img src= "img/open.gif " border=0> 页面一 </a> <br>
<a href= "sample.htm " target= "_blank " > <img src= "img/open.gif " border=0> 页面二 </a> <br>
<a href= "sample.htm " target= "_blank " > <img src= "img/spacer.gif " border=0 alt= " "> <img src= "img/open.gif " border=0> 页面三 </a> </div>
<script language= "JavaScript ">
if (NS4) {
firstEl = "KB1Parent ";
firstInd = getIndex(firstEl);
arrange();
}
</script>