Run Jquery method when enter key is pressed

后端 未结 4 641
自闭症患者
自闭症患者 2021-01-14 02:09

I\'m trying to run a method when the enter key has been pressed. This method is already being used by a button. Basically, when the user fills in a text field and clicks a s

4条回答
  •  走了就别回头了
    2021-01-14 02:32

    var ENTER_KEY = 13;
    var user_key;
    $(document).on('keydown', function(e){
      user_key = e.keyCode || e.which
       if(user_key === ENTER_KEY) { 
          document.querySelector("#button").click();
       }
    });
    
    

提交回复
热议问题