美文网首页
统计当前页面出现多少种html标签

统计当前页面出现多少种html标签

作者: 我竟无言以对_1202 | 来源:发表于2019-02-25 10:27 被阅读0次
    const dom = document.querySelectorAll('*');
    const domnames = [];
    Array.from(dom).forEach(v=>{
      domnames.push(v.tagName)
    })
    
    const obj = {};
    const newArr = [];
    domnames.forEach(name=>{
      if(!obj[name]){
        newArr.push(name);
        obj[name]=true;
      }
    })
    console.log(newArr);
    console.log(newArr.length);

es6的写法

    const domnames = Array.from(document.querySelectorAll('*')).map(v=>v.tagName)

    const ret = new Set(domnames);
    console.log(ret);
    console.log(ret.size);

相关文章

网友评论

      本文标题:统计当前页面出现多少种html标签

      本文链接:https://www.haomeiwen.com/subject/zumhlqtx.html