我正在努力與低調鼠標來改變背景圖像。 JSLint告訴我我的代碼是有效的,但它仍然不起作用。你能幫我嗎?有效的JS,但鼠標懸停不起作用
HTML
<div class="btn large contempt">
</div>
CSS
.btn.large.contempt {
background: url(http://dummyimage.com/100x100/83c79f/fff);
width: 100px;
height: 100px;
}
jQuery的
$(document).ready(function() {
$(".btn.large.contempt").bind('mouseover', function() {
$(".btn.large.contempt").attr('background','url(http://dummyimage.com/100x100/c78383/fff)');
});
});
任何原因你不這樣做與CSS? '.btn.large.contempt:hover { background:url(// dummyimage.com/100x100/c78383/fff); }' – Prescott 2011-12-29 08:22:55
@普雷斯科特是那麼簡單呢? – Leahcim 2011-12-29 08:30:27
它肯定是,比JavaScript更有效imo – Prescott 2011-12-29 08:31:44