遍历出文档内所有元素的tagName
2023-09-11 14:19:41 时间
//深度优先 function deepLogTagNames(parentNode){ console.log(parentNode.tagName); const childNodes=parentNode.childNodes; //过滤没有tagName的节点,遍历输出 Array.prototype.filter.call(childNodes,item=>item.tagName).forEach(itemNode=>{ deepLogTagNames(itemNode); }) } deepLogTagNames(document.body); //广度优先 function breadLogTagNames(root){ const queue=[root]; while(queue.length){ const currentNode=queue.shift(); const {childNodes,tagName}=currentNode; tagName&&console.log(currentNode.tagName);//这是what? //过滤没有tagName的节点 Array.prototype.filter.call(childNodes,item=>item.tagName).forEach(itemNode=>{ queue.push(itemNode); }) } } breadLogTagNames(document.body);
相关文章
- [Hadoop]Hive r0.9.0中文文档(一)之数据操作语句
- SenchaTouch 2.4 离线api文档下载
- Grid Infrastructure 启动的五大问题 (文档 ID 1526147.1)
- C# 对Word文档进行处理
- Atitit db analysis statistics tonjyi fsy数据库统计分析目录1. Atitit 数据库表与注释文档与统计(表,说明) 11.1. 获取表列表 数据库包含哪些
- 成功解决pdf文档加密后时间久了忘记密码—本文档有打开口令或修改口令—在线完美解决
- SQLAlchemy技术文档(中文版)-上
- 手把手教你AspNetCore WebApi:Swagger(Api文档)
- SpringBoot整合Freemarker导出word文档表格