display tree

    <img src="http://dl.iteye.com/upload/picture/pic/51639/26bce1a2-e039-3723-92a8-9f77d572d6e7.jpg" alt="" width="350" height="501"><br><!doctype html public "-//w3c//dtd html 4.01 transitional//en"> <br><html> <br><head> <br><meta http-equiv="content-type" content="text/html; charset=gb2312"> <br><title>网页教学网无限级树型菜单演示</title> <br><script type="text/javascript"> <br>//more javascript from http://www.webjx.com <br>var temp, temp2, cookiearray, cookiearray2, cookiecount; <br><br>function initiate(){ <br><br>  cookiecount=0; <br><br>  if(document.cookie){ <br><br>    cookiearray=document.cookie.split(";"); <br>    cookiearray2=new array(); <br><br>    for(i in cookiearray){ <br>      cookiearray2[cookiearray[i].split("=")[0].replace(/ /g,"")]=cookiearray[i].split("=")[1].replace(/ /g,""); <br>    } <br><br>  } <br><br>  cookiearray=(document.cookie.indexof("state=")>=0)?cookiearray2["state"].split(","):new array(); <br><br>  temp=document.getelementbyid("containerul"); <br><br>  for(var o=0;o<temp.getelementsbytagname("li").length;o++){ <br><br>    if(temp.getelementsbytagname("li")[o].getelementsbytagname("ul").length>0){ <br><br>      temp2 = document.createelement("span"); <br>      temp2.classname = "symbols"; <br>      temp2.style.backgroundimage = (cookiearray.length>0)?((cookiearray[cookiecount]=="true")?"url(tree/minus.png)":"url(tree/plus.png)"):"url(tree/plus.png)"; <br>      temp2.onclick=function(){ <br>        showhide(this.parentnode); <br>        writecookie(); <br>      } <br><br>      temp.getelementsbytagname("li")[o].insertbefore(temp2,temp.getelementsbytagname("li")[o].firstchild) <br><br>      temp.getelementsbytagname("li")[o].getelementsbytagname("ul")[0].style.display = "none"; <br><br>      if(cookiearray[cookiecount]=="true"){ <br>        showhide(temp.getelementsbytagname("li")[o]); <br>      } <br><br>      cookiecount++; <br><br>    } <br>    else{ <br><br>      temp2 = document.createelement("span"); <br>      temp2.classname = "symbols"; <br>      temp2.style.backgroundimage = "url(tree/page.png)"; <br><br>      temp.getelementsbytagname("li")[o].insertbefore(temp2,temp.getelementsbytagname("li")[o].firstchild); <br><br>    } <br><br>  } <br><br>} <br><br><br><br>function showhide(el){ <br><br>  el.getelementsbytagname("ul")[0].style.display=(el.getelementsbytagname("ul")[0].style.display=="block")?"none":"block"; <br><br>  el.getelementsbytagname("span")[0].style.backgroundimage=(el.getelementsbytagname("ul")[0].style.display=="block")?"url(tree/minus.png)":"url(tree/plus.png)"; <br><br>} <br><br><br><br>function writecookie(){ // runs through the menu and puts the "states" of each nested list into an array, the array is then joined together and assigned to a cookie. <br><br>  cookiearray=new array() <br><br>  for(var q=0;q<temp.getelementsbytagname("li").length;q++){ <br><br>    if(temp.getelementsbytagname("li")[q].childnodes.length>0){ <br>      if(temp.getelementsbytagname("li")[q].childnodes[0].nodename=="span" &amp;&amp; temp.getelementsbytagname("li")[q].getelementsbytagname("ul").length>0){ <br><br>        cookiearray[cookiearray.length]=(temp.getelementsbytagname("li")[q].getelementsbytagname("ul")[0].style.display=="block"); <br><br>      } <br>    } <br><br>  } <br><br>  document.cookie="state="+cookiearray.join(",")+";expires="+new date(new date().gettime() + 365*24*60*60*1000).togmtstring(); <br><br>} <br><br></script> <br><br><style type="text/css"><!-- <br><br>#containerul, #containerul ul{ <br>  text-align:left; <br>  margin:0; /* removes browser default margins applied to the lists. */ <br>  padding:0; /* removes browser default padding applied to the lists. */ <br>} <br><br>#containerul li{ <br>  margin:0 0 0 30px; /* a left margin to indent the list items and give the menu a sense of structure. */ <br>  padding:0; /* removes browser default padding applied to the list items. */ <br>  list-style-type:none; /* removes the bullet point that usually goes next to each item in a list. */ <br>} <br><br>#containerul .symbols{ /* various styles to position the symbols next to the items in the menu. */ <br>  float:left; <br>  width:12px; <br>  height:1em; <br>  background-position:0 50%; <br>  background-repeat:no-repeat; <br>} <br><br>--></style> <br></head> <br><br><body> <br><ul id="containerul"> <br>  <li> 网页教学网 <br>    <ul> <br>      <li> <a href="http://www.webjx.com/htmldata/sort/2.html">建站指南</a> <br>      </li> <br>      <li> <br>        <a href="http://www.webjx.com/htmldata/sort/3.html">网页制作</a> <br>      </li> <br>      <li> <br>        <a href="http://www.webjx.com/htmldata/sort/4.html">动画制作</a> <br>      </li> <br>    </ul> <br>  </li> <br>  <br>  <li> 网络编程 <br>    <ul> <br>      <li> <br>        <a href="http://www.webjx.com/htmldata/sort/24.html">asp.net</a> <br>      </li> <br>      <li> <br>        <a href="http://www.webjx.com/htmldata/sort/25.html">asp</a> <br>        <ul> <br>          <li> <br>            <a href="http://www.webjx.com/htmldata/sort/26.html">php</a> <br>          </li> <br>          <li> <br>            <a href="http://www.webjx.com/htmldata/sort/28.html">数据库</a> <br>          </li> <br>          <li> <br>            <a href="http://www.webjx.com/htmldata/sort/29.html">cgi</a> <br>          </li> <br>   <li> <br>            <a href="http://www.webjx.com/htmldata/sort/29.html">java网络编程</a> <br>      <ul> <br>          <li> <br>            <a href="http://www.webjx.com/htmldata/sort/26.html">jsp</a> <br>          </li> <br>          <li> <br>            <a href="http://www.webjx.com/htmldata/sort/28.html">j2ee</a> <br>          </li> <br>  </ul> <br>          </li> <br>        </ul> <br>      </li> <br>    </ul> <br>  </li> <br></ul> <br><br><p> <br>  <script type="text/javascript"> <br>initiate(); // this must be placed immediately after the menu in order to format it properly. <br></script> <br></p> <br><h3>树形菜单</h3> <br><p>说明:一个很容易制作树形菜单,你可以无限级的添加下级菜单,菜单是通过列表方式写成的 </p> <br></body> <br></html>
 
 

猜你喜欢

转载自qqchinaok.iteye.com/blog/1162264