< script type = "text/javascript" >
function mousePosition( 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;
function mouseMove( ev) {
ev = ev | | window. event;
var mousePos = mousePosition( ev) ;
document. getElementById( 'mouseXPosition' ) . value = mousePos. x;
document. getElementById( 'mouseYPosition' ) . value = mousePos. y;
}
< / script >
< fieldset >
< input id = mouseXPosition>
< input id = mouseYPosition>
< / fieldset >
Javascript鼠标坐标
最新推荐文章于 2023-07-04 23:05:56 发布