♣
关于一个网上xml树型菜单例子的问题:
例子如下:
<!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 & 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>
我的问题是刷新后怎样保持树形菜单的状态,就是我刷新前展开的是什么,刷新后还是。
谢谢各位老大了!!
分不够再加!!
· 网友精彩回答:
- 更多问题:
- · CListCtrl 插入多行,闪烁问题如何解决?
- · 如何利用ASP将XML数据岛导入到ACCESS里去2?
- · 菜鸟问题~~~~~送分送分~~~~~这个break;跳出跳到哪里去了?
- · VC调试工具DEBUG的用法介绍
- · 如何利用ASP将XML数据岛导入到ACCESS里去?
- · 郁闷中,散分。。。。。
- · 请教一个分组排序的问题?
- · 怎样给datagrid控件加一个自动增加的序号列?
- · asp.net用户控件有无开发工具?
- · 请问同一个word文件下如何生成两个目录?
- · 哪位给小弟发个verycd注册码,在下愿以一gmail注册号相还!
- · 因无人回,再发一贴:看看我的存贮过程哪句错了,有关临时表的。(可读性应该不差)
- · 源程序怎样在.net 2003下运行?看到效果?
- · [求助]关于用dispose释放内存的问题
- · 配ODBC
- · DWORD nByteswritten(0);这个什么意思?

