First, the use of hook events to capture
There are 3 keyboard events:
Keydown,keypress,keyup are pressed, press the not up, lift the keyboard.
$ (document). KeyUp (function (event) { if (Event.keycode ==13) { $ ("#submit"). Trigger ("click");} );
Recommended: KeyUp, prevent the notebook keyboard accidentally touch.
1. Some documents are written in this way:
$ (window). KeyDown (function () {...} )
XP system IE6 is not successful.
2. There is also input
$ ("input"). KeyDown (function () {...} )
This is the case when input gets the focus before the keyboard event can be heard.
Second, the form of form forms
1. Carriage return test:
<!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD"> <HTML> <Head> <Metahttp-equiv= "Content-type"content= "text/html; CHARSET=GBK"> <title>Submit Example-aspxhome.com</title> </Head> <Body> <H1>This demo demonstrates whether pressing ENTER in the text box triggers the form to be submitted</H1> <H2>By default, when a text box is submitted, regardless of whether the button type is submit or</H2> <formAction= "Http://www.csdn.net"> <inputtype= "text"> <inputtype= "button"value= "Submit"> </form> <H2>A text box how to do not commit, method is to add a hidden text box</H2> <formAction= "Http://www.csdn.net"> <inputtype= "text"> <inputtype= "text"style= "Display:none"> <inputtype= "button"value= "Submit"> </form> <H2>As long as there is a button for the type submit, a text box or multiple text boxes are submitted</H2> <formAction= "Http://www.csdn.net"> <inputtype= "text"> <inputtype= "Submit"value= "Submit"> </form> <H2>As long as there is a button for the type submit, a text box or multiple text boxes are submitted</H2> <formAction= "Http://www.csdn.net"> <inputtype= "text"> <inputtype= "text"> <inputtype= "Submit"value= "Submit"> </form> <H2>Multiple text boxes, do not commit, use the Type button buttons on the line</H2> <formAction= "Http://www.csdn.net"> <inputtype= "text"> <inputtype= "text"> <inputtype= "button"value= "Submit"> </form> <H2>FX and IE behave differently when using the button element</H2> <formAction= "Http://www.csdn.net"> <inputtype= "text"> <inputtype= "text"> <Button>Submit</Button> </form> <H2>The radio and CheckBox will also trigger the submit form under FX, and will not</H2> <formAction= "Http://www.csdn.net"> <inputtype= "text"> <inputtype= "Radio"name= "a"> <inputtype= "checkbox"name= "B"> <inputtype= "checkbox"name= "C"> <inputtype= "button"value= "Submit"> </form> <H2>The type is an image button, equivalent to the effect of type submit</H2> <formAction= "Http://www.csdn.net"> <inputtype= "text"> <inputtype= "text"> <inputtype= "image"src= "/images/logo.gif"> </form> </Body> </HTML>
2, in the form label to prohibit the ENTER key to submit:
<name= "form" action= " method=" POST " onkeydown= "if (event.keycode==13) return false;" OnSubmit = "return Checksubmit ();" >
3, you can add a hidden input box in the form.
4, can be added in type="test" onkeypress="Javascript:return gosearch ();" Method.
Reference:
Http://www.cnblogs.com/soundcode/p/6607746.html (the above content is transferred from this article)
http://blog.csdn.net/u010871655/article/details/51260878 (part of the above content is transferred from this article)
JavaScript control Enter to submit form (form) submission (GO)