美文网首页
事件对象

事件对象

作者: 冰点雨 | 来源:发表于2022-07-14 10:03 被阅读0次
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>事件对象</title>
        <style>
    
            #evg{
                width: 300px;
                height: 100px;
                border: 1px solid black;
            }
    
            #showMsg{
                width: 300px;
                height: 80px;
                border: 1px solid black;
            }
    
        </style>
        <script>
    
            window.onload = function(){
                var evg = document.getElementById('evg');
                var showMsg = document.getElementById('showMsg');
                evg.onmousemove = function(event){
    
                    // 解决事件对象兼容性问题
                    event = event ? event : window.event;
    
                    var x = event.clientX;
                    var y = event.clientY;
    
                    showMsg.innerHTML = "x="+x+",y="+y;
    
                }
            }
    
        </script>
    </head>
    <body>
    
        <div id="evg"></div>
        <br>
        <div id="showMsg"></div>
        
    </body>
    </html>
    

    相关文章

      网友评论

          本文标题:事件对象

          本文链接:https://www.haomeiwen.com/subject/dpknbrtx.html