Submitting a form on 'Enter' with jQuery?

后端 未结 14 1919
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 14:45

I have a bog-standard login form - an email text field, a password field and a submit button on an AIR project that\'s using HTML/jQuery. When I hit Enter on the form, the

14条回答
  •  一个人的身影
    2020-11-22 15:28

    $('.input').keypress(function (e) {
      if (e.which == 13) {
        $('form#login').submit();
        return false;    //<---- Add this line
      }
    });
    

    Check out this stackoverflow answer: event.preventDefault() vs. return false

    Essentially, "return false" is the same as calling e.preventDefault and e.stopPropagation().

提交回复
热议问题