jQuery背景图像CSS更改不起作用 [英] Jquery background image css change not working

查看:409
本文介绍了jQuery背景图像CSS更改不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想知道是否有人可以帮助您

wonder if anyone can help;

我正在尝试通过jquery这样更改元素的背景图片;

I am trying to change the background image of an element through jquery like this;

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

然而,当它呈现时,似乎在URL周围放置了语音标记,例如

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")');

这意味着图像不可见-如果我在Firebug中删除了语音标记,则图像会显示出来.

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

有什么想法吗?

谢谢

推荐答案

双引号不是必需的:

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

您应确保指定了有效的图像URL. 这是一个演示.

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

这篇关于jQuery背景图像CSS更改不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆