关于一个网上xml树型菜单例子的问题:

 所属目录:Java   |   类型:技术问答   |   时间:2007-05-21
 问题:

例子如下:  
  <!doctype   html   public   "-//w3c//dtd   html   4.0   transitional//en">  
  <html>  
  <head>  
  <title>   dstree   </title>  
  <meta   name="author"   content="starsjz@hotmail.com"   >  
  <style>  
  body,td{font:12px   verdana}  
  #treebox{background-color:#fffffa;}  
  #treebox   .ec{margin:0   5   0   5;}  
  #treebox   .hasitems{font-weight:bold;height:20px;padding:3   6   0   6;margin:2px;cursor:hand;color:#555555;border:1px   solid   #fffffa;}  
  #treebox   .items{height:20px;padding:3   6   0   6;margin:1px;cursor:hand;color:#555555;border:1px   solid   #fffffa;}  
  </style>  
  <base   href="http://vip.5d.cn/star/dstree/"   />  
  <script>  
  //code   by   star   20003-4-7  
  var   hc   =   "color:#990000;border:1px   solid   #cccccc";  
  var   sc   =   "background-color:#efefef;border:1px   solid   #cccccc;color:#000000;";  
  var   io   =   null;  
  function   inittree(){  
  var   rootn   =   document.all.menuxml.documentelement;  
  var   sd   =   0;  
  document.onselectstart   =   function(){return   false;}  
  document.all.treebox.appendchild(createtree(rootn,sd));  
  }  
  function   createtree(thisn,sd){  
  var   nodeobj   =   document.createelement("span");  
  var   upobj   =   document.createelement("span");  
  with(upobj){  
  style.marginleft   =   sd*10;  
  classname   =   thisn.haschildnodes()?"hasitems":"items";  
  innerhtml   =   "<img   src=expand.gif   class=ec>"   +   thisn.getattribute("text")   +"";  
   
  onmousedown   =   function(){  
  if(event.button   !=   1)   return;  
  if(this.getattribute("cn")){  
  this.setattribute("open",!this.getattribute("open"));  
  this.cn.style.display   =   this.getattribute("open")?"inline":"none";  
  this.all.tags("img")[0].src   =   this.getattribute("open")?"expand.gif":"contract.gif";  
  }  
  if(io){  
  io.runtimestyle.csstext   =   "";  
  io.setattribute("selected",false);  
  }  
  io   =   this;  
  this.setattribute("selected",true);  
  this.runtimestyle.csstext   =   sc;  
  }  
  onmouseover   =   function(){  
  if(this.getattribute("selected"))return;  
  this.runtimestyle.csstext   =   hc;  
  }  
  onmouseout   =   function(){  
  if(this.getattribute("selected"))return;  
  this.runtimestyle.csstext   =   "";  
  }  
  oncontextmenu   =   contextmenuhandle;  
  onclick   =   clickhandle;  
  }  
   
  if(thisn.getattribute("treeid")   !=   null){  
  upobj.setattribute("treeid",thisn.getattribute("treeid"));  
  }  
  if(thisn.getattribute("href")   !=   null){  
  upobj.setattribute("href",thisn.getattribute("href"));  
  }  
  if(thisn.getattribute("target")   !=   null){  
  upobj.setattribute("target",thisn.getattribute("target"));  
  }  
   
  nodeobj.appendchild(upobj);  
  nodeobj.insertadjacenthtml("beforeend","<br>")  
   
  if(thisn.haschildnodes()){  
  var   i;  
  var   nodes   =   thisn.childnodes;  
  var   cn   =   document.createelement("span");  
  upobj.setattribute("cn",cn);  
  if(thisn.getattribute("open")   !=   null){  
  upobj.setattribute("open",(thisn.getattribute("open")=="true"));  
  upobj.getattribute("cn").style.display   =   upobj.getattribute("open")?"inline":"none";  
  if(   !upobj.getattribute("open"))upobj.all.tags("img")[0].src   ="contract.gif";  
  }  
   
  for(i=0;i<nodes.length;cn.appendchild(createtree(nodes[i++],sd+1)));  
  nodeobj.appendchild(cn);  
  }  
  else{  
  upobj.all.tags("img")[0].src   ="endnode.gif";  
  }  
  return   nodeobj;  
  }  
  window.onload   =   inittree;  
  </script>  
   
  <script>  
  function   clickhandle(){  
  //   your   code   here    
  }  
  function   contextmenuhandle(){  
  event.returnvalue   =   false;  
  var   treeid   =   this.getattribute("treeid");  
  //   your   code   here  
  }  
  </script>  
  </head>  
  <body>  
  <xml   id=menuxml>  
  <?xml   version="1.0"   encoding="gb2312"?>  
  <dstreeroot   text="根节点"   open="true"   href="http://"   treeid="123">  
   
  <dstree   text="技术论坛"   open="false"   treeid="">  
  <dstree   text="5dmedia"   open="false"   href="http://"   target="box"   treeid="12">  
  <dstree   text="网页编码"   href="http://"   target="box"   treeid="4353"   />  
  <dstree   text="手绘"   href="http://"   target="box"   treeid="543543"   />  
  <dstree   text="灌水"   href="http://"   target="box"   treeid="543543"   />  
  </dstree>  
  <dstree   text="blueidea"   open="false"   href="http://"   target="box"   treeid="213">  
  <dstree   text="dreamweaver   &amp;   js"   href="http://"   target="box"   treeid="4353"   />  
  <dstree   text="flashactionscript"   href="http://"   target="box"   treeid="543543"   />  
  </dstree>  
  <dstree   text="csdn"   open="false"   href="http://"   target="box"   treeid="432">  
  <dstree   text="js"   href="http://"   target="box"   treeid="4353"   />  
  <dstree   text="xml"   href="http://"   target="box"   treeid="543543"   />  
  </dstree>  
  </dstree>  
   
  <dstree   text="资源站点"   open="false"   treeid="">  
  <dstree   text="素材屋"   href="http://"   target="box"   treeid="12"   />  
  <dstree   text="桌面城市"   open="false"   href="http://"   target="box"   treeid="213">  
  <dstree   text="壁纸"   href="http://"   target="box"   treeid="4353"   />  
  <dstree   text="字体"   href="http://"   target="box"   treeid="543543"   />  
  </dstree>  
  <dstree   text="msdn"   open="false"   href="http://"   target="box"   treeid="432">  
  <dstree   text="dhtml"   href="http://"   target="box"   treeid="4353"   />  
  <dstree   text="htc"   href="http://"   target="box"   treeid="543543"   />  
  <dstree   text="xml"   href=""   target="box"   treeid="2312"   />  
  </dstree>  
  </dstree>  
   
  </dstreeroot>  
  </xml>  
  <table   style="position:absolute;left:100;top:100;">  
  <tr><td   id=treebox   style="width:400px;height:200px;border:1px   solid   #cccccc;padding:5   3   3   5;"   valign=top></td></tr>  
  <tr><td   style="font:10px   verdana;color:#999999"   align=right>by   <font   color=#660000>star</font><br>   2003-4-8</td></tr>  
  </table>  
  </body>  
  </html>  
  我的问题是刷新后怎样保持树形菜单的状态,就是我刷新前展开的是什么,刷新后还是。  
  谢谢各位老大了!!  
  分不够再加!!

.

· 网友精彩回答:

处理 SSI 文件时出错
© 2006-2008 All Rights Reserved