捕获一个input键在页面上的任何地方

我需要在login页面的任何时候捕获一个Enter键。 它将启动login尝试。

使用jQuery,我将如何做到这一点? 我会链接到身体标签?

$(document).keypress(function(e) { if(e.which == 13) { // enter pressed } }); 

当一个键被按下时,keydown事件被触发。
当按下一个键并且该键通常产生一个字符值时,keypress事件被触发。

 $(document).keydown( function(event) { if (event.which === 13) { // login code here } });