【发布时间】:2010-07-14 07:41:00
【问题描述】:
我有一个类似的javascript
function getCursorPosition(e) {
e = e || window.event;
var cursor = {x:0, y:0};
if (e.pageX || e.pageY) {
cursor.x = e.pageX;
cursor.y = e.pageY;
}
else {
cursor.x = e.clientX +
(document.documentElement.scrollLeft ||
document.body.scrollLeft) -
document.documentElement.clientLeft;
cursor.y = e.clientY +
(document.documentElement.scrollTop ||
document.body.scrollTop) -
document.documentElement.clientTop;
}
return cursor;
}
document.onmouseup = function(e){
cursor = getCursorPosition();
alert(cursor.x + ':' + cursor.y);
};
此代码提醒单击光标的 X 和 Y 位置。这在 IE 7/8、Chrome/Safari、Opera 10 中运行良好。但在使用 firefox 4.0 beta 1 进行测试时,它无法正常工作。
在谷歌上搜索时,许多网站都给了我相同的代码。但它不适用于 ff 4.0b
这是 ff 4.0b 的错误吗?或者任何人都可以建议我另一个跨浏览器光标位置脚本吗?
【问题讨论】:
-
在 ie/opera 中...你有一个全局 window.event 对象,这就是它在这些平台上工作的原因...请参阅:quirksmode.org/js/introevents.html#link10
标签: javascript firefox cursor