javascript IE 和 Firefox 中的 window.onmousemove
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4257936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
window.onmousemove in IE and Firefox
提问by Honus Wagner
The purpose of the following code is that when the user is holding the SHIFT key down, some text will indicate that they are pressing it. It works great in Firefox, but IE does not acknowledge it.
以下代码的目的是当用户按住 SHIFT 键时,一些文本将指示他们正在按下它。它在 Firefox 中运行良好,但 IE 不承认它。
window.onmousemove = function(e) {
e = e || window.event;
var copyLabel = document.getElementById("<%= lblCopyEnabled.ClientID %>");
if (e.shiftKey) {
copyLabel.style.display = "inline";
ob_copyOnNodeDrop = true;
}
else {
copyLabel.style.display = "none";
ob_copyOnNodeDrop = false;
}
}
Advice is appreciated.
建议表示赞赏。
回答by Andy E
Despite what the MSDN docs say, onmousemovedoesn't work when applied to the windowobject. It should work in all browsers if you apply it to the documentobject instead:
尽管 MSDN 文档说了什么,onmousemove但在应用于window对象时不起作用。如果将其应用于document对象,它应该适用于所有浏览器:
document.onmousemove = function(e) {
e = e || window.event;
var copyLabel = document.getElementById("<%= lblCopyEnabled.ClientID %>");
if (e.shiftKey) {
copyLabel.style.display = "inline";
ob_copyOnNodeDrop = true;
}
else {
copyLabel.style.display = "none";
ob_copyOnNodeDrop = false;
}
}

