我查看了许多其他帖子,认为我正在使用建议的确切语法。然而,我的图片没有显示出来。我有一个jsfiddle。这是jsfiddle的问题吗?它在我正在工作的网站上也不起作用。
<div id="divtest">Hello</div>
<img id="imgtest" />
<img id="imgreal" src="http://www.premiumbeat.com/blog/wpcontent/uploads/2012/12/free.jpeg" />
var string = "url('http://www.premiumbeat.com/blog/wpcontent/uploads/2012/12/free.jpeg')";
alert(string)
document.getElementByID("divtest").style.backgroundImage = string;
document.getElementByID("imgtest").src = string;
document.getElementByID
!==document.getElementById
。 - Teemu