输出页面中所有的标签

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
 5     <title>Example</title>
 6 </head>
 7 <body>
 8     <div id="div1">
 9         <p><b>Hello</b> world!</p>
10         <ul>
11             <li>List item 1</li>
12             <li>List item 2</li>
13             <li>List item 3</li>
14         </ul>
15     </div>
16     <script type="text/javascript" src="test15.js"></script>
17 </body>
18 </html>
1 var div = document.getElementById("div1");
2 var iterator = document.createNodeIterator(div, NodeFilter.SHOW_ELEMENT, null, false);
3 var node = iterator.nextNode();
4 while (node !== null) {
5     console.log(node.tagName.toLowerCase()); //输出标签名
6     node = iterator.nextNode();
7 }
posted @ 2012-05-19 10:53  小猩猩君  阅读(300)  评论(0编辑  收藏  举报