How to trigger HTML button when you press Enter in textbox?

后端 未结 12 1283
悲哀的现实
悲哀的现实 2020-12-04 08:13

So the code that I have so far is:

&
12条回答
  •  生来不讨喜
    2020-12-04 09:12

    1. Replace the button with a submit
    2. Be progressive, make sure you have a server side version
    3. Bind your JavaScript to the submit handler of the form, not the click handler of the button

    Pressing enter in the field will trigger form submission, and the submit handler will fire.

提交回复
热议问题