注册
登录

您现在的位置是:首页 > 学无止境

Javascript鼠标坐标

木木彡82 2009-06-24 16:26:00 531人围观
script type="text/javascript">function mousePosition(ev){        if(ev.pageX || ev.pageY){                return {x:ev.pageX, y:ev.pa...
< 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 >

文章评论

  • 登录后评论

点击排行