window.event.x in ie 11在兼容性视图中给出错误的结果

时间:2014-02-13 08:55:57

标签: javascript-events cross-browser internet-explorer-11

我正在使用此代码获取鼠标的坐标。

MyObject.prototype._mouseMove = function (e) {
    var el,x;
    el = (e) ? e.target : window.event.srcElement;
    if (el.tagName == 'NOBR') { el = el.parentNode; }
    x = (e) ? e.pageX : window.event.x + this._eBody.scrollLeft;
    …
}

但使用IE11时使用兼容性视图我的X坐标错误。

有没有人有任何线索或绕过方法?

Tnx Gil

顺便说一句

我正在使用此标记

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8; charset=utf-8" />

但需要手动将页面添加到兼容性视图

1 个答案:

答案 0 :(得分:0)

找到解决方案

我正在使用window.event。 clientX 而不是window.event。 x 并且正在使用

x = (e) ? e.pageX : window.event.clientX + this._eBody.scrollLeft;