Http://www.cnblogs.com/luoyanli/archive/2012/07/09/2582650.html
1. Pressing ENTER will automatically submit the form when there is only one <input type= "text" name= ' name '/> in the form form.
<form id= ' Form1 ' action= ' a1.jsp ' method= ' post ' ><input type= ' text ' name= ' name '/></form>
Add a <input type= "text"/> Press Enter will not be automatically submitted, but the page shows a unintelligible input box very awkward, after searching from the Internet two solutions:
1; Add a <input type= ' text ' style= ' display:none '/> Do not display the input box, and then enter the following will not be submitted:
<form id= ' Form1 ' action= ' a1.jsp ' method= ' post ' ><input type= ' text ' name= ' name '/><input style= ' display: None '/></form>
2. Add a onkeydown event and then enter it again without displaying:
<form id= ' Form1 ' action= ' a1.jsp ' method= ' post ' ><input type= ' text ' name= ' name ' onkeydown= ' if (event.keycode== return false; ' /></form>
If you want to add a carriage return event, you can add a judgment submission form to the onkeydown event:
<form id= ' Form1 ' action= ' a1.jsp ' method= ' post ' ><input style= ' display:none '/><input type= ' text ' name= ' Name ' onkeydown= ' if (event.keycode==13) {gosubmit ();} '/></form>
Sometimes we want the enter key to be in the text box (input Element) to submit the form (form), but sometimes it's not desirable. such as search behavior, I hope to enter the keyword immediately after the key to submit the form, and some complex forms, you may want to avoid the enter error operation when the completion of the form to fill out the form to trigger the submission of forms.
To control these behaviors, do not need to use JS, the browser has helped us do these processing, here summarizes a few rules:
If there is a type= "submit" button in the form, the ENTER key will take effect. If there is only one type= "text" Input in the form, the enter takes effect regardless of the type of the button. If the button is not with input, but with a button, and no Type,ie is added, the default is type=button,fx default to Type=submit. Other form elements such as textarea, select Do not affect the Radio checkbox does not affect the triggering rules, but itself in the FX will respond to the enter, under IE do not respond. Type= "image" input, the effect is equivalent to type= "submit", do not know why the design of such a type, is not recommended, should be used to add a CSS background map appropriate.
Form press ENTER to submit automatically (GO)