1 // 获取dom树 2 var getElement = (node, array) => { 3 if (node && node.nodeType ===1){ 4 array.push(node.tagName) 5 } 6 for (let i=0;i<node.childNodes.length;i++){ 7 if(node.childNodes[i].nodeType ===1){ 8 getElement(node.childNodes[i], array) 9 } 10 } 11 } 12 window.onload = ()=>{ 13 let html = document.getElementsByTagName(‘html‘)[0] 14 let array = [] 15 getElement(html, array) 16 console.log(array) 17 }
原文地址:https://www.cnblogs.com/StruggleStudyhard/p/8941989.html
时间: 2024-10-10 17:13:48