通过深度优先遍历算法,可以依次获取每个后代节点的对象。

顺序:有子元素先获取子元素,再获取兄弟元素

主要有2步骤:

//1.创建节点迭代器对象(parent是要遍历的节点)

var iterator = document.createNodeIterator(parent, NodeFilter.SHOW_ELEMENT, null, false);

//2.反复调用iterator的nextNode方法跳到下一个

do{

  var node = iterator.nextNode();

  if(node !=  null) console.log(node.nodeName);

  else break;

}while(true);

以上也可以使用递归实现,但递归效率较低,不建议使用。

最新文章

  1. powershell例子
  2. 在 Visual Studio 等编辑器/IDE中自动切换输入法,不需要手动的有没有?
  3. iOS App 获取从后台返回前台时的页面
  4. ZOJ 1067 Color Me Less
  5. EJB (not bound)
  6. ios7新特性2--多任务提升
  7. java: cannot execute binary file
  8. iOS 开发 Message Digest Algorithm 5(MD5加密)
  9. javascript重点笔记
  10. [数据挖掘] - 聚类算法:K-means算法理解及SparkCore实现
  11. postgresql事务
  12. openstack-ntp时间同步服务
  13. virtualBox导入虚拟机启动报错
  14. Tomcat问题:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined ,At least one of these environment variable is needed to run this program
  15. smarty中调用php内置函数
  16. vlc源码分析(七) 调试学习HLS协议
  17. 关于mybatis的思考(1)——mybatis的使用实例
  18. js es6 map 与 原生对象区别
  19. apk签名相关文章
  20. 查看Linux是32位还是64位的方法

热门文章

  1. python之路(列表,元组)
  2. 0级搭建类006-Oracle Solaris 安装 (10.13) 公开
  3. python3练习100题——056
  4. npm vs yarn
  5. 假期学习【五】RDD编程实验四
  6. AcWing 10. 有依赖的背包问题
  7. 多线程启动selenium,报NameError: name '__file__' is not defined
  8. 在电脑上用chrome浏览器调试android手机里的网页代码时,无法看到本地加载的js文件
  9. 用C#调用外部DLL
  10. Learning to See in the Dark论文阅读笔记