Capture an Enter Key Pressed anywhere on the page

前端 未结 2 403
粉色の甜心
粉色の甜心 2020-12-08 01:39

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 would I l

相关标签:
2条回答
  • 2020-12-08 02:05

    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 讨论(0)
  • 2020-12-08 02:13
    $(document).keypress(function(e) {
      if(e.which == 13) {
        // enter pressed
      }
    });
    
    0 讨论(0)
提交回复
热议问题