输出页面中指定的标签 2

 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></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="test17.js"></script>
17 </body>
18 </html>
 1 var div = document.getElementById("div1");
 2 var walker = document.createTreeWalker(div, NodeFilter.SHOW_ELEMENT, null, false);
 3
 4 walker.firstChild();
 5 walker.nextSibling();
 6
 7 var node = walker.firstChild();
 8 while (node !== null) {
 9  console.log(node.tagName);
10 node = walker.nextSibling();
11 }

IE9以下还是不兼容 NodeFilter 此代码

posted @ 2012-05-19 13:36  小猩猩君  阅读(141)  评论(0编辑  收藏  举报