zoukankan      html  css  js  c++  java
  • 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;
                 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>
  • 相关阅读:
    咖啡叫软件开发--界面组日志06-总结
    咖啡叫软件开发--界面组日志05
    咖啡叫软件开发--界面组日志04
    咖啡角软件开发--界面组日志03
    咖啡角软件开发--界面组日志02
    咖啡角软件开发--界面组日志01
    实时控制软件 第三次作业
    第二次作业
    《构建之法:现代软件工程》第一章有感
    第一天
  • 原文地址:https://www.cnblogs.com/whzym111/p/6070418.html
Copyright © 2011-2022 走看看