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>