我有几个div,我想为其生成css背景图像。他们会在盘旋时改变。是的,我知道我可以在css中轻松做到这一点,但它需要在jQuery中完成。jquery更改悬停的背景图像
代码:
$(document).ready(function() {
$('.hoverBox').css('background', 'url(img/box' + id + '.jpg)')
$('.hoverBox').hover(function(){
$(this).css('background', 'url(img/box' + this.id + '_back.jpg)')
},
function(){
$(this).css('background', 'url(img/box' + this.id + '.jpg)')
});
});
HTML是这样的:
<div class="hoverBox" id="benefits">
content</div>
<div class="hoverBox" id="installation">
content</div>
<div class="hoverBox" id="shoponline">
content</div>
这应该是很容易的,但我似乎无法使它工作。
援助将不胜感激! TIA。
什么似乎是问题? – Reigel 2010-09-17 00:53:35
我认为这是:'url(img/box'+ id +'.jpg)',但我无法弄清楚我要出错的地方。最初的背景图像不显示,当然,悬停图像也不显示。 – circey 2010-09-17 00:57:53