标签:ons pre get size 获取 class 遍历 length 节点
方法1 // 获取所有节点 var tags = document.getElementsByTagName("*") //遍历获取所有节点的类型 是DIV 还是A let tagnames = [] let tagnames = [] for (let i = 0; i < tags.length; i++) { const element = tags[i]; tagnames.push(element.tagName) } //去重的逻辑 let obj = {} let count = 0 for(let j=0; j<tagnames.length;j++){ if(!obj[tagname]){ count +=1 obj[tagname] = true } } 方法2 let tags = [...document.getElementsByTagName("*")].map(v=>v.tagName) let count = new Set(tags).size console.log(count) let count = new Set([...document.getElementsByTagName("*")].map(v=>v.tagName)).siz e
标签:ons pre get size 获取 class 遍历 length 节点
原文地址:https://www.cnblogs.com/musi03/p/10298120.html