开发者

Capture an Enter Key Pressed anywhere on the page

开发者 https://www.devze.com 2023-03-27 13:01 出处:网络
I need to capture an Enter Key press at any time anywhere on a logon page. It will initiate a logon attempt.

I need to capture an Enter Key press at any time anywhere on a logon page. It will initiate a logon attempt.

Using jQuery, how would I accomplish this? And w开发者_如何转开发ould I link it to the body tag?


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


The keydown event is fired when a key is pressed down.
The keypress event is fired when a key is pressed down and that key normally produces a character value.

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

精彩评论

暂无评论...
验证码 换一张
取 消