我需要使用jQuery定义div的背景 colored颜色 :hover,但以下方法似乎不起作用:
$(".myclass:hover div").css("background-color","red");
我怎样才能得到同样的结果?必须用jQuery完成这项工作,这一点很重要,但由于某些原因,它不起作用.有什么建议吗?谢谢
我需要使用jQuery定义div的背景 colored颜色 :hover,但以下方法似乎不起作用:
$(".myclass:hover div").css("background-color","red");
我怎样才能得到同样的结果?必须用jQuery完成这项工作,这一点很重要,但由于某些原因,它不起作用.有什么建议吗?谢谢
I would suggest to use CSS over jquery ( if possible) otherwise you can use something like this
$("div.myclass").hover(function() {
$(this).css("background-color","red")
});
您可以根据需要更改 Select 器.
正如@A.Wolff所 comments 的,如果你想对多个类使用这个悬停效果,你可以这样使用它
$(".myclass, .myclass2").hover(function(e) {
$(this).css("background-color",e.type === "mouseenter"?"red":"transparent")
})