在IE和Firefox中的window.onmousemove

7
以下代码的目的是当用户按住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? - stan229
1个回答

19

尽管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/


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接