开发者

Prototype Javascript Set Background Image

开发者 https://www.devze.com 2023-03-22 04:18 出处:网络
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 n

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 + ')'});
0

精彩评论

暂无评论...
验证码 换一张
取 消