开发者

Jquery background image css change not working

I am trying to change the b开发者_StackOverflow中文版ackground image of an element through jquery like this;

$j(this).css('background-image','url(images/client_box_grad.gif)');

However when it renders it seems to drop speech marks around the the url, eg

$j(this).css('background-image','url("images/client_box_grad.gif")');

And this means the image isn't visible - if I remove the speech marks in Firebug then the image shows up.

Any ideas ?


The double quotes are not necessary:

$(this).css('background-image', 'url(/images/client_box_grad.gif)');

You should make sure that you have specified a valid image url. Here's a demo.


This is what I had to do to get it to work:

$(function(){
$('body').css({backgroundImage : 'url(/media/bill.jpg)'});
});


Try these:

$(this).css('background-image','url(images/client_box_grad.gif)');

// OR
$(this).css('background', 'url("images/client_box_grad.gif")');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜