FBJS setStyle( {backgroundImage}) not working?
The Problem:
I can't see the images and I don't know why.The FBJS code
url = "http://www.domain.de/image.gif";
myImg = document.createElement('img');
myImg.setStyle( {backgroundImage: 'url('+url+')' });
document.getElementById('wrapper').appendChild(myImg);
The rendered html
<img style="ba开发者_开发问答ckground-image: url("http://www.domain.de/image.gif";);">
Try modifying your code like this and specify the src
attribute of the image:
url = "http://www.domain.de/image.gif";
myImg = document.createElement('img');
myImg.setSrc(url);
document.getElementById('wrapper').appendChild(myImg);
You're really thing to set the background image of an img
element? That seems...odd. Are you sure you don't just want to do a normal img
element (Sarfraz may have you covered there if so) or specify the background image of the wrapper element? E.g.:
url = "http://www.domain.de/image.gif";
document.getElementById('wrapper').setStyle( {backgroundImage: 'url('+url+')' });
I've marked this CW because I've never done any FBJS, so could be talking through my hat. :-) If it helps, it helps.
精彩评论