js_使用js读取link外部样式

<link rel="stylesheet" href="https://at.alicdn.com/t/c/font_1826665_p96ije5uc2f.css" crossorigin>
var linkStyle = document.getElementsByTagName("link")[0];
var sheet = linkStyle.sheet || linkStyle.styleSheet;
let reg = /(\S{1,})::before$/i
const oBody = document.body
Array.prototype.forEach.call(sheet.cssRules, rule => {
  if (rule.selectorText && rule.selectorText !== '.iconfont') {
    const oI = document.createElement('i')
    oI.classList.add('iconfont')
    oI.classList.add(reg.exec(rule.selectorText)[1].slice(1))
    oBody.appendChild(oI)
  }
})
posted @ 2023-10-09 22:43  Syinho  阅读(27)  评论(0编辑  收藏  举报