當前位置:編程學習大全網 - 編程軟體 - 編程確定當前鼠標的位置坐標。

編程確定當前鼠標的位置坐標。

& ltscript type = " text/JavaScript " & gt;

函數鼠標位置(ev){

if(ev.pageX || ev.pageY){

return {x:ev.pageX,y:ev . pakey };

}

返回{

x:ev . clientx+document . body . scroll left-document . body . client left,

y:ev . clienty+document . body . scroll top-document . body . client top

};

}

函數鼠標移動(ev){

ev = ev | | window.event

var mouse pos = mouse position(ev);

document.getElementById('xxx ')。value = mousePos.x

document.getElementById('yyy ')。value = mousePos.y

}

document.onclick = function(){

預警(121212);

}

document . onmousemove = mouseMove;

& lt/script & gt;

x:& lt;input id = " XXX " type = " text "/& gt;y:& lt;input id = " yyy " type = " text "/& gt;

這兩個輸入框顯示了鼠標的坐標值。

  • 上一篇:manchi什麽意思?
  • 下一篇:51單片機編程題,幫我編個程序。
  • copyright 2024編程學習大全網