所以它改变了背景图像,但没有改变背景颜色。 无论如何要指出我的代码中的问题?
JavaScript:
$("#menu a").hover(function() {
$(this).addClass("hover");
}, function() {
$(this).removeClass("hover");
});
CSS:
.hover {
background-color: white;
background-position: top center;
background-image: url("img/dot.png");
background-repeat: no-repeat;
color: red;
}
最佳答案
如上所述...如果您只添加以下 css,它会处理它。
a:hover {
background-color: white;
background-position: top center;
background-image: url("img/dot.png");
background-repeat: no-repeat;
color: red;
}
:hover是一个伪css类,你可以在任何东西上使用它,而不需要添加jquery/js来支持它。
关于javascript - 背景颜色没有改变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9178435/