发信人: tantom() 
整理人: eagle(2000-12-24 10:00:39), 站内信件
 | 
 
 
E.例子五:显示出页中的元素结构  
 <HTML> 
 <HEAD><TITLE>Elements: Hierarchy</TITLE> 
 <SCRIPT LANGUAGE="JScript"> 
 function showHierarchy() { 
     var depth = 0; 
     var msg = document.all(0).tagName; 
     for (i=1; i<document.all.length; i++) { 
         if (document.all(i-1).contains(document.all(i))==true) { 
             depth = depth + 1; 
         } else { 
             var elParent = document.all(i-1).parentElement; 
             for ( ; depth>0; depth--) { 
                 if (elParent.contains(document.all(i))==true) 
                     break; 
                 elParent = elParent.parentElement; 
             } 
         } 
         msg = msg + "\n"; 
         for (j=1; j<=depth; j++) 
             msg = msg + "  "; 
         msg = msg + document.all(i).tagName; 
     } 
     alert("这个页面中包含的元素为\n" + msg); 
 } 
 </SCRIPT> 
 </HEAD> 
 <BODY onload="showHierarchy()"> 
 <H1>欢迎光临</H1> 
 <P>你看到预想的结果 了吗. 
 </BODY> 
 </HTML> 
  -- ※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.105.76.164]
  | 
 
 
 |