【发布时间】:2016-08-24 11:11:01
【问题描述】:
嘿,伙计们,我有以下脚本,当我移动鼠标时,它会为我提供光标位置。 此脚本在 chrome、FF 甚至 IE 8 中都可以正常工作(没有 !doctype html)
如果将 !DOCTYPE html 添加到 html 页面。 它给了我对象不支持此属性错误。并且下面给定的行导致了问题
document.captureEvents(Event.MOUSEMOVE);
如何使用 IE 8 中包含的 !DOCTYPE html 解决此问题。
window.onload = init;
function init() {
if (window.Event) {
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = getCursorXY;
}
function getCursorXY(e) {
document.getElementById('cursorX').value = (window.Event) ? e.pageX :
event.clientX + (document.documentElement.scrollLeft ?
document.documentElement.scrollLeft : document.body.scrollLeft);
document.getElementById('cursorY').value = (window.Event) ? e.pageY : event.clientY
+ (document.documentElement.scrollTop ? document.documentElement.scrollTop :
document.body.scrollTop);
}
【问题讨论】:
-
AFAIK,对于 9 以下的 IE,您应该使用
clientX/clientY。 stackoverflow.com/questions/11042275/… -
这个链接帮助了我 stackoverflow.com/questions/6307307/…> 非常感谢大家!!
标签: javascript html internet-explorer-8