Making Enter key on an HTML form submit instead of activating button

前端 未结 7 1595
北恋
北恋 2021-02-03 16:33

I have an HTML form with a single submit input, but also various button elements. When the user presses the \'enter\' key, I\'d expect it to actually s

7条回答
  •  心在旅途
    2021-02-03 17:14

    $("form#submit input").on('keypress',function(event) {
      event.preventDefault();
      if (event.which === 13) {
        $('button.submit').trigger('click');
      }
    });
    

提交回复
热议问题