I am trying to set background image of a div through prototype javascript.The image_path
variable returning exact file location.If I use that variable in setStyle
it returning only the variable name not the image.What am i doing wrong?
<script type="text/javascript">// 开发者_如何学运维<![CDATA[
function changed()
{
var options=$('first');
if(options.value.endsWith('.jpg'))
{
var image_name=options.value;
var image_path="http://localhost/dev/skin/frontend/default/wireframe/images/"+image_name;
//alert(image_path);
$('firstdiv').setStyle({backgroundImage: 'url(image_path)'});
return;
}
else {
$('firstdiv').setStyle({backgroundColor:options.value});
}
}
// ]]></script>
$('firstdiv').setStyle({backgroundImage: 'url(image_path)'});
you're using image_path
as a part of a string. You want
$('firstdiv').setStyle({backgroundImage: 'url(' + image_path + ')'});
精彩评论