<div class="div1" style=" background:#CCC;"><div>
<div class="div1" style=" background:#AAA;"><div>
<div class="div1" style=" background:#EEE;"><div>
<div id="div4"><div>
$(".class").hover(function(){
$("#div4").css("background",$(this).css("background"));
},function(){
$("#div4").css("background","");
})
我这里做的是鼠标移到前面三个DIV上的时候,第四个DIV的背景就显示当前DIV背景的颜色。
追问
您看是这样吗 为什么 没效果
追答$(".div").hover(function () {
$("#div4").css("background", $(this).css("background"));
}, function () {
$("#div4").css("background", "");
});
不好意思刚才写错了, 应该是这样, 你要给DIV一个宽高这样才有效果。