DOM深度优先遍历算法
2024-09-06 21:34:39
通过深度优先遍历算法,可以依次获取每个后代节点的对象。
顺序:有子元素先获取子元素,再获取兄弟元素
主要有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);
以上也可以使用递归实现,但递归效率较低,不建议使用。
最新文章
- powershell例子
- 在 Visual Studio 等编辑器/IDE中自动切换输入法,不需要手动的有没有?
- iOS App 获取从后台返回前台时的页面
- ZOJ 1067 Color Me Less
- EJB (not bound)
- ios7新特性2--多任务提升
- java: cannot execute binary file
- iOS 开发 Message Digest Algorithm 5(MD5加密)
- javascript重点笔记
- [数据挖掘] - 聚类算法:K-means算法理解及SparkCore实现
- postgresql事务
- openstack-ntp时间同步服务
- virtualBox导入虚拟机启动报错
- 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
- smarty中调用php内置函数
- vlc源码分析(七) 调试学习HLS协议
- 关于mybatis的思考(1)——mybatis的使用实例
- js es6 map 与 原生对象区别
- apk签名相关文章
- 查看Linux是32位还是64位的方法
热门文章
- python之路(列表,元组)
- 0级搭建类006-Oracle Solaris 安装 (10.13) 公开
- python3练习100题——056
- npm vs yarn
- 假期学习【五】RDD编程实验四
- AcWing 10. 有依赖的背包问题
- 多线程启动selenium,报NameError: name '__file__' is not defined
- 在电脑上用chrome浏览器调试android手机里的网页代码时,无法看到本地加载的js文件
- 用C#调用外部DLL
- Learning to See in the Dark论文阅读笔记