随笔 - 154  文章 - 60  trackbacks - 0
<2007年10月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

声明:

该blog是为了收集资料,认识朋友,学习、提高技术,所以本blog的内容除非声明,否则一律为转载!!

感谢那些公开自己技术成果的高人们!!!

支持开源,尊重他人的劳动!!

常用链接

留言簿(3)

随笔分类(148)

随笔档案(143)

收藏夹(2)

其他

学习(技术)

观察思考(非技术)

搜索

  •  

最新评论

阅读排行榜

评论排行榜

<button onclick=s.moveNext()>next</button><button onclick=s.movePre()>pre</button><button onclick=s.reLoad()>reload</button>
<script>
function eyunTree(Tname)
  {if(typeof(Tname) != "string" || Tname == "")
     throw(new Error(-1, '创建类实例的时候请把类实例的引用变量名传递进来!'));
   this.O=null;
   this.tree="";
   this.nodes=new Array();
   this.header="<table border='0'  height='20' cellspacing='0' cellpadding='1'>\r\n";
   this.footer="</table>\r\n";
   this.style= "<style type='text/css'>\r\n";
   this.style+="  td{white-space: nowrap;font:9pt/150% '宋体';}\r\n";
   this.style+="  .on{cursor:hand;background-color:#B5BED6;border:1px solid #08246B;}\r\n";
   this.style+="  .click{cursor:hand;background-color:#FFFFFF;border:1px solid #B5BED6;}\r\n";
   this.style+="</style>";
   this.addNode=function (parent,text,hasChild,href,target)
                  {if(hasChild!=1 && arguments.length!=5)
                     throw(new Error(-2, '参数错误!'));
                   var nodeHeader="  <tr style='display:none'>\r\n    <td><table style='margin-left:15' border='0'  height='20' cellspacing='0' cellpadding='1'>\r\n";
                   var nodeFooter="</table></td>\r\n  </tr>\r\n";
                   var treeHead="  <tr>\r\n";
                   treeHead+=   "    <td><span onclick='"+Tname+".nodeClick(this)' onmouseout='"+Tname+".nodeOut(this)' onmouseover='"+Tname+".nodeOver(this)'";
                   var treeFoot="</span></td>\r\n";
                   treeFoot+=   "  </tr>\r\n";
                   var treeNode=treeHead+"hasChild='"+hasChild+"'";
                   if(hasChild!=1)
                     {treeNode+=" href='"+href+"' target='"+target+"'";
                      var src="comm/img/tree/leaf.gif";
                     }
                   else
                     var src="comm/img/tree/shrink.gif"
                   treeNode+="><img src='"+src+"' align='absmiddle'>"+text+treeFoot;
                   if(parent=="root")
                      treeNode=this.header+treeNode;
                   if(hasChild==1)
                     {treeNode+=nodeHeader;
                     }
                   if(this.tree!="" && this.nodes.length!=0)
                     {if(parent=="root")
                        {while(this.nodes.length>0)
                           {this.tree+=nodeFooter;this.nodes.length--}
                         this.tree+=this.footer;
                        }
                      else
                        {if(this.nodes[this.nodes.length-1]!=parent && this.tree.lastIndexOf(parent)!=this.tree.length-parent.length)
                           {while(this.nodes.length-1>0)
                             {if(this.nodes[this.nodes.length-1]!=parent)
                                this.tree+=nodeFooter;
                              else
                                break;
                              this.nodes.length--
                             }                             
                           }
                         }
                     }
                   if(this.nodes[this.nodes.length-1]!=parent)
                     this.nodes[this.nodes.length]=parent;
                   this.tree+=treeNode;
                   return treeNode;
                  }
    this.nodeOver=function (o)
                  {o.oldClass=o.className;
                   o.className="on";
                  }
    this.nodeOut=function (o)
                   {o.className=o.oldClass;
                   }
    this.nodeClick=function (o)
                     {if(o.hasChild=="1")
                        {if(o.type=="open")
                           this.treeClose(o);
                         else
                           this.treeOpen(o);
                        }
                      else
                        {tmpA.href=typeof o.href=="undefined"?"#":o.href;
                         tmpA.target=typeof o.target=="undefined"?"_self":o.target;
                         tmpA.click();
                        }
                      if(this.O!=null)
                        this.O.className=this.O.oldClass="";
                      this.O=o;
                      o.oldClass=o.className="click";
                     }
    this.treeClose=function (o)
                     {o=o.parentElement.parentElement;
                      o.nextSibling.style.display="none";
                      o.firstChild.firstChild.firstChild.src="comm/img/tree/shrink.gif";
                      o.firstChild.firstChild.type="close";
                     }

    this.treeOpen=function (o)
                    {o=o.parentElement.parentElement;
                     o.nextSibling.style.display="";s
                     o.firstChild.firstChild.firstChild.src="comm/img/tree/unwrap.gif";
                     o.firstChild.firstChild.type="open";
                    }
    this.moveNext=function ()
                    {var o=document.getElementsByTagName("SPAN");
                     var l=o.length;
                     if(this.O==null)
                       {o[0].click(o[0]);  
                        return true;
                       }
                     for(var i=0;i<l;i++)
                       if(o[i].className==this.O.className)
                         break;
                    if(i<l-1)
                      o[i+1].click(o[i+1]);
                    else
                      o[i].click(o[i]);
                    }
    this.movePre=function ()
                   {var o=document.getElementsByTagName("SPAN");
                    var l=o.length;
                    if(this.O==null)
                      {o[0].click(o[0]);  
                       return true;
                      }
                    for(var i=0;i<l;i++)
                      if(o[i].className==this.O.className)
                        break;
                    if(i<l && i>0)
                      {var oP=o[i-1].parentElement;
                       var oC=null;
                       while(oP!=document.body)
                         {if(oP.tagName=="TR" && oP.style.display=="none")
                            {oP.style.display="";
                             oP.previousSibling.firstChild.firstChild.firstChild.src="comm/img/tree/unwrap.gif";
                             oP.previousSibling.firstChild.firstChild.type="open";
                            }
                          oP=oP.parentElement;
                         }
                       o[i-1].click(o[i-1]);
                      }
                    else
                      o[0].click(o[0]);
                   }
    this.reLoad=function ()
                  {var o=document.getElementsByTagName("SPAN");
                   var l=o.length;
                   if(this.O==null)
                     {o[0].click(o[0]);  
                      return true;
                     }
                   for(var i=0;i<l;i++)
                     if(o[i].className==this.O.className)
                       break;
                   if(i<l)
                     o[i].click(o[i]);
                   else
                     o[0].click(o[0]);
                  }
    this.show=function ()
                {document.writeln(this.style);
                 document.writeln(this.tree);
                 document.writeln("<a id='tmpA'></a>");
                }
   }
  var s=new eyunTree("s")
  var n=s.addNode("root","testRoot1",1)
  var a=s.addNode(n,"testNode1",1)
  s.addNode(a,"testNodeChild1",0,"http://www.iecn.net","_blank")
  s.addNode(a,"testNodeChild2",0,"http://www.iecn.net","_blank")
  var t=s.addNode(a,"testNodeChildNode1",1)
  s.addNode(t,"testNodeChild1",0,"http://www.iecn.net","_blank")
  s.addNode(t,"testNodeChild2",0,"http://www.iecn.net","_blank")
  s.addNode(n,"testChild2",0,"http://www.iecn.net","_blank")
  s.addNode(n,"testChild3",0,"http://www.chinaddv.com","_blank")
  var o=s.addNode("root","testRoot2",1)
  s.addNode(o,"testChild1",0,"http://www.chinaddv.com","_blank")
  d=s.addNode(o,"testChild2",1)
  s.addNode(d,"testChild1",0,"http://www.chinaddv.com","_blank")
  e=s.addNode(d,"testChild1",1)
  s.addNode(e,"testChild1",0,"http://www.chinaddv.com","_blank")
  s.addNode(e,"testChild1",0,"http://www.chinaddv.com","_blank")
  s.addNode(e,"testChild1",0,"http://www.chinaddv.com","_blank")
  s.addNode(d,"testChild1",0,"http://www.chinaddv.com","_blank")
  s.addNode(o,"testChild3",0,"http://www.chinaddv.com","_blank")
  s.show();
</script>

posted on 2007-10-09 09:53 lk 阅读(2459) 评论(0)  编辑  收藏 所属分类: ajax&js

只有注册用户登录后才能发表评论。


网站导航: