2014-05-12 97 views
0

我已经在a:hover上设置了背景图像,我需要在mouseover(基于条件)的基础上对另一图像进行覆盖。使用jQuery更改悬停的背景

我想这一点,但它不工作:

$("a").mouseover(function() { 
    $(this).css('background-image', 'url(../images/new2.png'); 
}); 

...它仍然显示了使用CSS应用到a:hover之一。

+1

你能证明这一点“不工作'?因为它真的应该,我想。 –

+1

您错过了url的结尾括号 – mohamedrias

+0

$(this).css('background-image','url(../ images/new2.png)');将做的伎俩 – mohamedrias

回答

4

您需要为您的网址

+0

就是这样!男人,我不应该工作得这么晚,发生这么多愚蠢的错误! – 3zzy

0

延伸@sahbeewah答案右括号,关闭支架为您的网址

$("a").mouseover(function() { 
    $(this).css('background-image', 'url(../images/new2.png)'); 
}); 

您还可以使用CSS

a:hover{ 
    background-image : url(../images/new2.png); 
}