如何从鼠标捕获功能获取返回值?
function getMousePosition(e)
{
positionX = e.pageX;
positionY = e.pageY;
if (positionX < 0){positionX = 0;}
if (positionY < 0){positionY = 0;}
return positionX + " " + positionY;
}
如
var mousePositions = getMousePosition(e);
最佳答案
function getMousePosition(e)
{
e = e || event //for cross browser implentation
var positionX = e.pageX;
var positionY = e.pageY;
if (positionX < 0){positionX = 0;}
if (positionY < 0){positionY = 0;}
return {positionX: positionX, positionY: positionY};
}
现在您可以执行此操作
var mousePositions = getMousePositions(someEventObject);
alert(mousePositions.positionX);
alert(mousePositions.positionY);
关于javascript - 如何从鼠标捕获功能获取返回值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2960400/