Button Click event fires when pressing Enter key in different input (no forms)

后端 未结 6 2106
离开以前
离开以前 2020-12-12 21:42

This logic is firing when pressing \"Enter\" in the \"Amount\" input, and I don\'t believe it should (it doesn\'t in Chrome). How can I prevent this, and if not prevent it

6条回答
  •  醉酒成梦
    2020-12-12 22:14

    IE thinks any button element is a submit button (whether you have a form or not). It also handles the press of the Enter key in a form element as an implicit form submission. So, since it thinks you are trying to submit your form, it figures it'll help you out and fire the click event on (what it thinks is) the submit button.

    You can attach a keyup event to either the input or the button and check for the Enter key (e.which === 13) and return false;

提交回复
热议问题