<!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>
    

 

posted on 2021-09-15 00:28  ——light  阅读(1411)  评论(0编辑  收藏  举报