日期:2014-05-16  浏览次数:20401 次

【问】Jquery 中的 mouseover和mouseout
能举个关于切换样式的例子么谢谢

------解决方案--------------------
HTML code

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="gb2312" />
        <title></title>        
        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <style>
            div {
                width:100px; height:100px;
                background:#eee;
            }
        </style>
    </head>
    <body>
        <div id="test"></div>
        <script>
            $('#test').mouseover(function(){
                $(this).css('backgroundColor', 'red');
            }).mouseout(function(){
                $(this).css('backgroundColor', '#eee');
            })
        </script>
    </body>
</html>

------解决方案--------------------
有现成的模拟hover伪类,何必费那个劲还加onmouseover和onmouseout?

HTML code
<html>
    <head>
        <title>Jquery Hover</title>
    </head>
     <script src="http://code.jquery.com/jquery.js"></script>
    <script>
        $(function (){
            $("button").hover(
                function(){
                    alert("do onMouseover");
                },
                function(){
                    alert("do onMouseout");
                }
            );
        })
    </script>
    <body>
        <button>Button</button>
    </body>
</html>

------解决方案--------------------
上面已有答案了。