- <html>
- <head>
- <script type="text/javascript">
- function getCoordinates(e){
- x=e.clientX;
- y=e.clientY;
- document.getElementById("xycoordinates").innerHTML="当前坐标为: (X轴:" + x + ",Y轴:" + y + ")";
- }
- function clearCoordinates(){
- document.getElementById("xycoordinates").innerHTML="";
- }
- </script>
- </head>
- <body>
- <div style="width:199px;height:99px;border:1px solid #c3c3c3" onmousemove="getCoordinates(event)" onmouseout="clearCoordinates()"></div>
- <div id="xycoordinates"></div>
- </body>
- </html>
这样更简单(整个页面坐标):
- <html>
- <head>
- <script type="text/javascript">
- function getCoordinates(e){
- x=e.clientX;
- y=e.clientY;
- document.getElementById("xycoordinates").innerHTML="当前坐标为: (X轴:" + x + ",Y轴:" + y + ")";
- }
- </script>
- </head>
- <body onmousemove="getCoordinates(event)">
- <div id="xycoordinates"></div>
- </body>
- </html>
本文转自许琴 51CTO博客,原文链接:http://blog.51cto.com/xuqin/959082,如需转载请自行联系原作者