jquery press ENTER to implement a simple instance of form submission _jquery

Source: Internet
Author: User

This article introduces you to the user entered the information directly after the return of the form submitted to the jquery implementation method, there is a need to know friends can come in for reference.

There are 3 keyboard events:

jquery Keyboard Event Reference:

1, KeyDown ()

The KeyDown event is triggered when the keyboard is pressed.

2, KeyUp ()

The KeyUp event triggers when the key is released, which is what happens when you press the keyboard

3, KeyPress ()

The KeyPress event triggers when the keystroke is hit, which we can understand to press and lift the same key

The correct code is:

$ (document). KeyUp (function (event) {
 if (Event.keycode ==13) {
  $ ("#submit"). Trigger ("click");
 }
);
 

Recommended: KeyUp, to prevent the notebook keyboard accidentally touch the

1. Some documents are written in this way:

$ (window). KeyDown (function () {
...
} )
 

XP system IE6 is unsuccessful.

2. There is also the input

$ ("input"). KeyDown (function () {
...
} )
 

In this case, the keyboard event can only be heard when input gets the focus.

The example form is as follows:

<form name= "LoginForm" id= "LoginForm" method= "POST" >
 <div>   
   <p> user name: <input type= "Text" Name= "username"/></p>
   <p> Password: <input type= "password" name= "password"/></p>
   < P><input type= "button" value= "" class= "log_btn"/></p>
 </div>
</form>

Juqery Implementation Method:

$ ("#loginform"). KeyDown (function (e) {
 var e = e | | event,
 keycode = E.which | | e.keycode;
 if (keycode==13) {
 $ (". Log_btn"). Trigger ("click");
 }
);
 

The above jquery press ENTER to implement form submission Simple example is small series to share all the content, hope to give you a reference, also hope that we support cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.