1. When there is only one in the form, pressing the Enter key will automatically submit the form.
Add one more
Pressing Enter will not automatically submit, but it is awkward to display an unintelligible input box on the page. I then found two solutions from the Internet:
(1) Add a
The input box will not be displayed, and it will not be submitted after pressing Enter:
(2) Add an onkeydown event, and it will not be displayed after pressing Enter:
If you want to add a carriage return event, you can add a judgment submission form in the onkeydown event:
Sometimes we want to press the Enter key in the text box (input element) to submit the form (form), but sometimes we don't want this. For example, for search behavior, you want to directly press the Enter key after entering the keywords to submit the form immediately. For some complex forms, you may want to avoid accidentally pressing the Enter key to trigger the form submission before completing the form filling.
To control these behaviors, there is no need to resort to JS. The browser has already done this for us. Here are a few rules:
If there is a button of type="submit" in the form, the Enter key will take effect.
If there is only one input of type="text" in the form, regardless of the button type, the Enter key will take effect.
If the button is not input, but button, and no type is added, the default is type=button in IE and type=submit in FX.
Other form elements such as textarea and select will not be affected, and the radio checkbox will not affect the triggering rules, but it will respond to the Enter key under FX but not under IE.
The input of type="image" has the same effect as type="submit". I don't know why such a type is designed. It is not recommended. It is more appropriate to use CSS to add a background image.