html实现树形结构(精简代码)

 1<style>
 2    A{margin-left:20px;width:100px;border:1px solid gray;float:left;clear:both;cursor:hand;}    
 3    B{width:100px;border:1px solid gray;float:left;clear:both;cursor:default;}
 4
</style>
 5<>A</B>
 6    <>1</A><A>2</A>
 7<>B</B>
 8    <>4</A><>5</A><>6</A> 
 9 
10<SCRIPT LANGUAGE="JavaScript">
11var B_Tags=document.getElementsByTagName("B" );
12for(var i=0;i<B_Tags.length;i++)
13{
14    B_Tags[i].onclick=function (){
15        change(event.srcElement);
16        event.cancelBubble=true;
17    }

18}

19var c=0;
20function change(obj)
21{    
22    var myobj=obj.nextSibling;    
23    while(myobj.tagName!="B" && myobj.tagName!="SCRIPT" )
24    {            
25        if(myobj.tagName!=null)
26        {    
27            myobj.style.display=(myobj.style.display=="none")?"":"none";
28        }
        
29        myobj=myobj.nextSibling;        
30    }

31}

32
</SCRIPT>

posted on 2007-10-18 14:09  小子好黑  阅读(4948)  评论(0编辑  收藏  举报

导航