js 获取鼠标位置的两种方法

时间:2021-09-16 06:32:19   收藏:0   阅读:49

    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>获取鼠标位置</title>
        </head>
        <body>
            <input id="aa"/>
            <input id="bb"/>
        </body>
    </html>

 

 下面两种选一种就可以了。


    <script>
        onmousemove = function (a) {
            document.getElementById(‘aa‘).value = a.x;
            document.getElementById(‘bb‘).value = a.y;
        };
    </script>
    

 


    <script>
        addEventListener("mousemove", function (a) {
            document.getElementById(‘aa‘).value = a.x;
            document.getElementById(‘bb‘).value = a.y;
        };
    </script>
    

 

原文:https://www.cnblogs.com/lgxblogs/p/15270413.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!