showCatalog = () => {//食堂百科-docx页面添加目录
        let docxStr = document.getElementById("docx").innerHTML,
            reg = /<a href="(.+?)">(.+?)<\/a>/gi,
            regCont = /<a[^>]*href=['"]([^"]*)['"][^>]*>(.*?)<\/a>/gi,
            nodeArr = docxStr.match(reg),//a标签的数组
            hrefArr = [],//截取出来的href属性
            codeArr = [],//截取的a标签内容
            catalogAryList = [],//目录总数据
            hrefReg = /(<a\b[^>]+\bhref=")(\S*)("[^>]*>)(.*?)(<\/a>)/;
        if (nodeArr !== null && nodeArr !== [] && nodeArr !== undefined) {
            for (let key in nodeArr) {
                let str = nodeArr[key];
                if (str.indexOf("#") >= 0) {
                    hrefArr.push((hrefReg.exec(str))[2])
                    codeArr.push((hrefReg.exec(str))[4])
                }
            }
            hrefArr.map((item, index) => {
                catalogAryList.push({
                    id: index,
                    href: item,//链接
                    msg: codeArr[index]//内容
                })
            })
            catalogObj.catalogAry = catalogAryList;
        } else {
           // console.log('empty')
        }

    }

 

相关文章:

  • 2022-02-09
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-18
猜你喜欢
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2022-01-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案