首页 > Web开发 > 详细

js 获取鼠标位置坐标

时间:2015-03-03 20:09:52      阅读:224      评论:0      收藏:0      [点我收藏+]
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>javascript获得鼠标位置</title> 
</head> 
<body> 
<div id="lijj"  style="width:500px;height:500px;background:#000;">
</div>

<script> 
function mouseMove(ev) 
{ 
    Ev= 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}; 
    } 
    return{ 
        x:ev.clientX + document.body.scrollLeft - document.body.clientLeft, 
        y:ev.clientY + document.body.scrollTop - document.body.clientTop 
    }; 
} 
document.getElementById(lijj).onclick = mouseMove; 

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

 

js 获取鼠标位置坐标

原文:http://www.cnblogs.com/xinlinux/p/4311687.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!