2010-11-23 72 views
6

以下代码的作用是,当用户按住SHIFT键时,一些文本会指出他们正在按下它。它在Firefox中效果很好,但IE不承认它。window.onmousemove在IE和Firefox中

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

建议表示赞赏。

+0

什么版本的IE浏览器,你定位? – stan229 2010-11-23 15:55:50

回答

15

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