Submitting a form on 'Enter' with jQuery?

后端 未结 14 1912
爱一瞬间的悲伤
爱一瞬间的悲伤 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:23

    Is there any reason you have to hook and test for the enter key?

    Couldn't you simply add a

     
    

    to your form and have it naturally be submitted when enter is pushed? You could even then hook the form's onsubmit action and call a validation function from there if you wanted...

    You could even use the onsubmit as a test to see if your form is being submitted, but it won't work if you call form.submit().

提交回复
热议问题