Suppose I have a div
<div id="div_a" style="background-image:url('xxx')"></div>
Then I can get the url info by using
document.getElementById("div_a").style.backgroundImage
to get its url info.
However if the style is defined in CSS the code above would return blank
Anything wrong with it?
您正在寻找的是计算样式getComputedStyle
window.getComputedStyle(document.getElementById("div_a"), null).getPropertyValue('background-image')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.