鼠标事件(jQuery方法)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>鼠标事件</title>
        <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
        <script type="text/javascript">
            $(function() {
                $("input[type='button']")
                    .css("width", "280px")
                    .css("height", "100px")
                    .css("font-size", "24pt");

                $("input[type='button']:eq(0)")
                    .mouseover(fnOver)
                    .mouseout(fnOut);

                $("input[type='button']:eq(1)")
                    .click(function() {
                        $('h1').html('点击了鼠标!');
                    });

                $("input[type='button']:eq(2)")
                    .dblclick(function() {
                        $('h1').html('双击了鼠标!');
                    });
                $("input[type='button']:eq(3)")
                    .mousedown(function() {
                        $('h1').html('按下了鼠标!');
                    })
                    .mouseup(function() {
                        $('h1').html('松开了鼠标!');
                    });
                $("div").mousemove(function() {
                    $("div").text(event.x + "," + event.y);
                });
            });

            function fnOver() {
                $("h1").html("鼠标移动到按钮上了!");
            }

            function fnOut() {
                $("h1").html("鼠标移开了!");
            }

            function fnMove() {
                $("div").text(event.x + "," + event.y);
            }
        </script>
    </head>

    <body>
        <h1></h1>
        <input type="button" value="测试悬停" />
        <input type="button" value="测试点击" />
        <input type="button" value="测试双击" />
        <input type="button" value="测试鼠标按键" />
        <div style="border: double 3px red; 400px; height: 300px;">
        </div>
    </body>

</html>

原文地址:https://www.cnblogs.com/zhouguoshuai/p/8192207.html