JS获取鼠标坐标

来源:互联网 发布:淘宝店铺监控多久解除 编辑:程序博客网 时间:2024/05/18 03:05
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><%@ page language="java" %><%@ page contentType="text/html;charset=UTF-8"%>    <head>    <title>鼠标位置</title>    <script type="text/javascript">        function $(id){            return document.getElementById(id);        }           function body_onclick(e){            event = e||window.event;            $("x-position").value=event.x;            $("y-position").value=event.y;        }    </script>    <style>        .position{            width:1000px;            height:500px;            text-align:center;            color: gold;            background-color: #6090dd;            font-size:24pt;            margin: 0 auto;        }    </style>    </head>    <body onmousemove="body_onclick(event)">        <div class="position">            当前鼠标坐标:            x<input value="0" id="x-position" size="6"/>            y<input value="0" id="y-position" size="6"/>        </div>    </body></html>
0 0
原创粉丝点击