zoukankan      html  css  js  c++  java
  • JavaScript事件对象

    如何获取事件对象?

    在给元素绑定事件的时候,在事件的function函数的参数列表中添加一个参数---习惯取名为event,这个event就是事件对象

    <!DOCTYPE html>
    <html>
        <head>
        <meta charset="UTF-8">
        <style>
            div#a{
                margin-bottom: 10px;
                border:1px solid black;
                100px;
                height:100px;
            }
            div#b{
                border:1px solid black;
                200px;
                height:100px;
            }
        </style>
        <!--引入jQuery库-->
        <script type="text/javascript" src="../lib/jquery-1.7.2.js"></script>
        <script type="text/javascript">
          
        $(function(){
            //原生js获取事件对象
            // window.onload=function(){
            //     document.getElementById("a").onclick=function(event){
            //         console.log(event);
            //     }
            // }
            //jQuery代码获取事件对象
            // $(function(){
            //     $("#b").click(function(event){
            //         console.log(event);
            //     });
            // });
    
            $(function(){
                $("#a").bind("mouseover mouseout",function(event){
                    if(event.type=="mouseover"){
                        console.log("鼠标移入");
                    }
                    else{
                        console.log("鼠标移出");
                    }
                })
            });
        });
        </script>
        </head>
        <body>
            <div id="a"></div>
            <div id="b"></div>
        </body>
    </html>
    
    
  • 相关阅读:
    OpenCV 使用FLANN进行特征点匹配
    OpenCV 特征描述
    OpenCV 特征点检测
    OpenCV 亚像素级的角点检测
    OpenCV Shi-Tomasi角点检测子
    OpenCV Harris 角点检测子
    OpenCV 模板匹配
    OpenCV 直方图计算
    OpenCV 直方图均衡化
    OpenCV 仿射变换
  • 原文地址:https://www.cnblogs.com/fate-/p/14706535.html
Copyright © 2011-2022 走看看