1. Pressing ENTER will automatically submit the form when there is only one <input type= "text" name= "name"/> in form forms.
Copy Code code as follows:
<form id= "Form1" action= "post.php" method= "POST" >
<input type= "text" name= "name"/>
</form>
Add one more
Copy Code code as follows:
Press ENTER will not be automatically submitted, but the page shows an unintelligible input box is very awkward, and then found two solutions from the Internet:
(1) Add a
Copy Code code as follows:
<input style= "Display:none" type= "text"/>
The input box is not displayed and will not be submitted after the carriage return:
Copy Code code as follows:
<form id= "Form1" action= "post.php" method= "POST" >
<input type= "text" name= "name"/>
<input style= "Display:none"/>
</form>
(2) Add a onkeydown event, and it will not be displayed after the carriage return:
Copy Code code as follows:
<form id= "Form1" action= "post.php" method= "POST" >
<input type= "text" name= "name" onkeydown= "if (event.keycode==13) return false;" />
</form>
If you want to add a carriage return event, you can add a judgment submission form to the onkeydown event:
Copy Code code as follows:
<form id= "Form1" action= "post.php" method= "POST" >
<input style= "Display:none"/>
<input type= "text" name= "name" onkeydown= "if (event.keycode==13) {gosubmit ();}"/>
</form>
Sometimes we want the return key to knock on the text box (input Element) to submit the form, but sometimes we don't want to. For example, search behavior, you want to enter the keyword immediately after the press return directly to submit the form, and some complex forms, you may want to avoid the return key error operation in the unfinished form filled out when it triggered the form submission.
To control these behaviors, no need to use JS, the browser has helped us do these processing, here summed up a few rules:
If there is a type= "submit" button in the form, the ENTER key takes effect.
If there is only one type= "text" Input in the form, the ENTER key takes effect, regardless of the type of the button.
If the button is not used with input, it is type,ie with a button, and the default is TYPE=BUTTON,FX defaults to Type=submit.
Other form elements such as textarea, select Do not affect, radio checkbox does not affect the trigger rule, but itself in the FX will respond to enter, under IE does not respond.
Type= "image" input, the effect is equivalent to type= "submit", do not know why the design of such a type, not recommended, you should use CSS to add a background map appropriate.