jQuery学习-鼠标事件

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>鼠标事件</title>
            <script src="js/jquery.js"></script>
        
        <style>
        .me{ 
            
            border: 1px solid red;
            margin-top: 75px;
            width: 400px;
            height: 150px;
            background-color: #ccc;
            overflow: auto;
        }
        </style>
        
        <script type="text/javascript">    
            //页面加载完成简写形式
            $(function(){
                $("button").on("click",function(){
                    
                    $("input").css("background-color","lightblue");
                });
                
                
                //移动进入的时候触发mouseover,移出时触发mouseout
                //在jQuery中提供了个hover() 带两个参数 是 鼠标移动进入时执行的函数和鼠标移动出执行的函数
                $(".me").hover(function(){
                    //移入执行的函数
                    $(this).css("background-color","red");
                },function(){
                    //移出执行的函数
                    $(this).css("background-color","#ccc");
                })
                
                //给整个文档绑定鼠标移动事件
                //在事件处理函数中有一个默认参数 事件对象event 它包含了事件产生的信息
                $(document).on("mousemove",function(event){
                    
                    var x=event.pageX//鼠标在文档X坐标
                    var y=event.pageY//鼠标Y坐标
                    $("#div1").text("X:"+x+"Y:"+y);
                    
                });
                
                //双击放大DIV
                $(".me").on("dblclick",function(){
                    
                    $(this).width(600);
                    $(this).height(300);
                });
                
                //停止双击事件向父层传播
                $("button").dblclick(function(event){
                    
                    event.stopPropagation();
                });
            
            })
        
        </script>
    </head>
    <body>
        <div>
            <div id="div1">在这里显示坐标</div>
            <div class="me">事件测试案例
            <input type="text" /><br>
            <button>提交</button>
            </div>
        </div>
    </body>
</html>

 

posted @ 2016-11-16 17:18  whzym111  阅读(150)  评论(0编辑  收藏  举报