回答

3

为了使你的代码跨浏览器,你应该:

document.onkeydown = function(e) { 
    e = e || window.event; 
    var keyCode = e.keyCode || e.which; 

    if(keyCode == 83) { alert("hello"); } 
} 

检查上面的代码片段here

+0

它的工作原理。我真的看起来像这样。 非常感谢。 :-) – Aajahid 2009-09-11 22:15:34

+0

不客气SHAKTI。 – CMS 2009-09-11 22:26:51

2
+0

谢谢你的链接。真的很有帮助。这将有助于我更多地了解它们。我非常喜欢学习新的东西。 – Aajahid 2009-09-11 22:17:00

0

你允许使用jQuery?因为这将工作:

$(window).keydown(function(event){ 
    if(event.keyCode == 83){ 
      alert('hello'); 
    } 
}); 

Partially boosted from here

+1

谢谢,但我不喜欢使用jQuery。 – Aajahid 2009-09-11 22:20:08