const result = []
function getUniqueTag(root) {
const rt = [...root]
rt.forEach(item => {
if(!result.includes(item.tagName)) {
result.push(item.tagName)
}
if(item.children && (0 in item.children)) {
getUniqueTag(item.children)
}
})
return result
}
// const arr = [
// {
// tagName:'div1',
// children:[
// {tagName:'div4',}
// ]
// },
// {
// tagName:'div2',
// },
// {
// tagName:'div3',
// },
// ]
// 1.子集递归查找;
// 2.判断不同;
// 3.返回结果;
// 4.先判断children 还是先存储tag
getUniqueTag(document.querySelectorAll('*'))
【获取页面所有的不重复tag】
最新推荐文章于 2023-11-01 14:28:03 发布