提取页面上用到的所有CSS
代码如下:
var result = [];
[].forEach.call(document.styleSheets, function(item1) {
debugger
if (item1.cssRules) {
[].forEach.call(item1.cssRules, function(item2) {
var sign = false
if (!item2.selectorText) sign = false
else if (document.querySelector(item2.selectorText)) sign = true
else {
var str = String(item2.selectorText).replace(/\:+[^:\,]*/ig, '')
try { if (document.querySelector(str)) sign = true } catch (e) {console.log(e)}
var list = str.split(',')
list.forEach(function (item3) {
try { if (document.querySelector(item3)) sign = true } catch (e) {console.log(e)}
})
}
if (sign) result.push(item2.cssText)
})
} else {
console.log('[crossorigin]: ' + item1.href)
}
});
result;
var out = document.getElementById('out')
if (!out) {
document.body.insertAdjacentHTML('afterEnd', '123')
out = document.getElementById('out')
}
out.innerHTML = result.join('')
伪类及伪元素
http://www.alloyteam.com/2016/05/summary-of-pseudo-classes-and-pseudo-elements/
优秀组件
https://ant.design/components/form-cn/
http://www.runoob.com/bootstrap/bootstrap-modal-plugin.html