如果你不关心 IE ≤6,你可以使用纯 CSS ...
.forum:hover { background-color: #380606; }
使用 jQuery,通常最好为这种样式创建一个特定的类:
.forum_hover { background-color: #380606; }
然后在鼠标悬停时应用该类,并在鼠标悬停时将其删除。
$('.forum').hover(function(){$(this).toggleClass('forum_hover');});
如果不能修改类,可以将原来的背景色保存在.data()(Example):
$('.forum').data('bgcolor', '#380606').hover(function(){
var $this = $(this);
var newBgc = $this.data('bgcolor');
$this.data('bgcolor', $this.css('background-color')).css('background-color', newBgc);
});
或
$('.forum').hover(
function(){
var $this = $(this);
$this.data('bgcolor', $this.css('background-color')).css('background-color', '#380606');
},
function(){
var $this = $(this);
$this.css('background-color', $this.data('bgcolor'));
}
);