【问题标题】:window.onmousemove in IE and FirefoxIE 和 Firefox 中的 window.onmousemove
【发布时间】:2010-11-23 15:49:49
【问题描述】:

以下代码的目的是当用户按住 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;
        }
    }

不胜感激。

【问题讨论】:

  • 你的目标是什么版本的IE?

标签: javascript javascript-events


【解决方案1】:

尽管 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;
    }
}

演示:http://jsfiddle.net/AndyE/aUxSz/

【讨论】:

    猜你喜欢
    • 2016-02-08
    • 2018-01-30
    • 1970-01-01
    • 1970-01-01
    • 2012-09-14
    • 2014-11-09
    • 1970-01-01
    • 1970-01-01
    • 2013-03-08
    相关资源
    最近更新 更多