这是我有史以来的第一个问题,请表现出爱意!
我试图从div元素中抓取背景图片,并在每次按下底部时将其附加到div中。下面是样机代码:
<div class="img"></div>
.img {
background: url("local image file");
}
function addImage(imageSrc) {
var imageSrc = document.getElementByClassName('img')[0].getComputedStyle.background
}
我找不到在后台url(“”)中获取本地路径的方法。有人可以帮忙吗?我只知道香草Javascript。
谢谢!
使用:
window.getComputedStyle(document.getElementsByClassName('img')[0]).getPropertyValue('background')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句