|
用JavaScript生成树结构(二) |
| 下面给出完整的演示程序: <html> <head> <title>Tree</title> <META content="text/html; charset=gb2312" http-equiv=Content-Type> <style type=text/css> .p1{FONT-FAMILY:宋体;FONT-SIZE:14px;COLOR:#0000FF} A{FONT-FAMILY:宋体; FONT-SIZE:14px;TEXT-DECORATION:none;COLOR:#0000FF} IMG{VERTICAL-ALIGN:text-top} </style> <script language=javascript> <!-- function w(txt){document.write(txt);} var root,ID=0; var na=new CHILD(); var gif="/images/"; var curfocus; function CHILD() //节点孩子集合定义 { this.total=0; this.Add=Add; this.Delete=Delete; return this; } function Add(childnode) { this[this.total]=childnode; this.total++; } function Delete(childnode) { for(var i=0;i<this.total;i++) if(childnode==this[i])break; if(i!=this.total)this.total--; for(;i<this.total;i++) this[i]=this[i+1]; } function NODE(name) //节点定义 { this.id=ID; this.name=name; this.imgopsm=""; this.imgclbg=""; this.imgclsm=""; this.parent=""; this.child=new CHILD(); this.link=""; this.target=""; this.display=true; na.Add(this); ID++; return this; } |