js获取区域坐标_坐标

 

  1. <html> 
  2. <head> 
  3. <script type="text/javascript">  
  4.     function getCoordinates(e){ 
  5.     x=e.clientX; 
  6.     y=e.clientY; 
  7.     document.getElementById("xycoordinates").innerHTML="当前坐标为: (X轴:" + x + ",Y轴:" + y + ")"; 
  8.     } 
  9.       
  10.     function clearCoordinates(){ 
  11.     document.getElementById("xycoordinates").innerHTML=""
  12.     } 
  13. </script> 
  14. </head> 
  15.  
  16. <body> 
  17. <div style="width:199px;height:99px;border:1px solid #c3c3c3" onmousemove="getCoordinates(event)" onmouseout="clearCoordinates()"></div> 
  18. <div id="xycoordinates"></div> 
  19. </body> 
  20. </html> 

 

 

这样更简单(整个页面坐标):

 

  1. <html> 
  2. <head> 
  3. <script type="text/javascript">  
  4.     function getCoordinates(e){ 
  5.         x=e.clientX; 
  6.         y=e.clientY; 
  7.         document.getElementById("xycoordinates").innerHTML="当前坐标为: (X轴:" + x + ",Y轴:" + y + ")"; 
  8.     } 
  9. </script> 
  10. </head> 
  11.  
  12. <body onmousemove="getCoordinates(event)"> 
  13.     <div id="xycoordinates"></div> 
  14. </body> 
  15. </html>