javascript获取鼠标当前位置坐标 详细出处参考:http://www.jb51.net/article/27204.htm

来源:互联网 发布:阿里云邮箱个人 编辑:程序博客网 时间:2024/06/06 00:25

鼠标X轴: 鼠标Y轴: 详细出处参考:http://www.jb51.net/article/27204.htm

 

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>javascript获得鼠标位置</title> 
</head> 
<body> 


<script> 
function mouseMove(){ 
var ev= window.event; 
var mousePos = mouseCoords(ev); 
 
document.getElementById("xxx").value = mousePos.x; 
document.getElementById("yyy").value = mousePos.y; 



function mouseCoords(ev){ 
if(ev.pageX || ev.pageY){ 
return {x:ev.pageX, y:ev.pageY}; 



 



</script> 


鼠标X轴: 
<input id=xxx type=text> 
鼠标Y轴: 
<input id=yyy type=text> 


<div style="width:200px;height:200px;border:red solid 2px" onmousemove="mouseMove()">


</div>
</body> 

0 0