zoukankan      html  css  js  c++  java
  • 输出页面中指定的标签 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 此代码

  • 相关阅读:
    SpringMVC—对Ajax的处理(含 JSON 类型)(2)
    md5加密(1)
    js生成邀请码(2)
    SpringMVC---依赖注入与面向切面
    初识json
    java集合类(2)
    springmvc与struts2的区别
    模拟14
    NOIP模拟13
    NOIP模拟12
  • 原文地址:https://www.cnblogs.com/qzsonline/p/2508836.html
Copyright © 2011-2022 走看看