document.getElementById("").style
获取的是元素行间设置的样式,不能获取到css中设置的样式。如果要获取css中设置的样式,可以试试getComputedStyle
(标准浏览器)或者currentStyle
(ie低版本)
let target = document.getElementById('target')
// 获取目标伪元素样式
getComputedStyle(target, 'before').backgroundColor
// 获取目标元素样式
getComputedStyle(target, null).backgroundColor