jQuery改变背景的悬停 [英] jQuery changing background on hover

查看:107
本文介绍了jQuery改变背景的悬停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码

<div id="addQuesion">
    <ul id="aQul">
        <li class="aQli"></li>
        <li class="aQli"></li>
    </ul>
</div>

我的jQuery是

$(document).ready(function(){
    $(".aQli").mouseover(function(){

    });
    $(".aQli").mouseout(function(){

    });
});

我希望当鼠标悬停在li上时,背景应该是红色的,背景应该回到白色。如何做到这一点?

I want when hovering over a li, the background should be red, and on exit from that li, the background should return to white. How can I do this?

推荐答案

你必须使用jQuery吗?

Do you have to use jQuery?

更正确的方式是在您的课程中加入悬停样式。

The more "correct" way would be to add a hover style to your class.

.aQli:hover{
   background-color: red;   
}​

请参阅此处的示例。 http://jsfiddle.net/maurice_butler/5q6QM/

See here for an example. http://jsfiddle.net/maurice_butler/5q6QM/

这篇关于jQuery改变背景的悬停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆