js获取鼠标当前位置,兼容ie和firefox

 
更多

js获取鼠标当前位置,兼容ie和firefox,具体见如下代码:

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> 
<title>js获取鼠标当前位置</title> 
</head> 
<body> 
<script type="text/javascript"> 
function mouseMove(ev){ 
	Ev= ev||window.event;
	var mousePos=mouseCoords(Ev);
	document.getElementById("www.phpernote.com").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.onmousemove=mouseMove;
</script> 
鼠标X轴坐标: 
<input id="www.phpernote.com" type="text" /> 
鼠标Y轴坐标: 
<input id="yyy" type="text" /> 
</body>
</html>
打赏

本文固定链接: https://www.cxy163.net/archives/4557 | 绝缘体

该日志由 绝缘体.. 于 2013年05月23日 发表在 未分类 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: js获取鼠标当前位置,兼容ie和firefox | 绝缘体
关键字: , , , ,

js获取鼠标当前位置,兼容ie和firefox:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter