'Enter key' wont submit form in Firefox, but will in Chrome, why?

前端 未结 2 1997
故里飘歌
故里飘歌 2020-12-18 04:03

I have a form, very basic, and when I hit enter key nothing happens in firefox, but in google chrome it submits. Haven\'t tried other browsers yet...

Nothing happens

相关标签:
2条回答
  • 2020-12-18 04:23

    As Diodeus mentioned, you need an <input type="submit"> tag in your form if you want to use the ENTER key to submit the form.

    The reason that your reset_pager function is not firing on the onsubmit event is because the onsubmit event is never fired. Though it's somewhat counter-intuitive, using the submit() method on a form (as you're doing in your reset_and_subm function) will not cause the onsubmit event to fire.

    You have a couple options:

    1. You can add an <input type="submit"> to your form and put all your logic in an onsubmit callback function.

    2. Watch all keypress events on the form. If the ENTER key is pressed or the button is clicked, then call a function that does all the stuff you want to happen before submitting the form and then call submit() on the form.

    0 讨论(0)
  • 2020-12-18 04:26

    Enter for submit is only triggered if <input type="submit> exists on the form. You can add a hidden one for this purpose, but keep in mind that it will submit the form and bypass the onclick event you're looking to capture. You'll need to patch into the onsubmit action of the form to run your function.

    0 讨论(0)
提交回复
热议问题