Enter event on the jquery press Disk

Source: Internet
Author: User

Next, we use Jquery to implement the Enter key to switch the focus. This code is tested in popular browsers such as IE7, IE8, Firefox 3, Chrome 2, and Safari 4.
The development tool used is the Microsoft VS2010 + Jquery framework.

The implementation steps are as follows:

1. First reference the Jquery class library

<Script src = "Scripts/jquery-1.4.1.min.js" type = "text/javascript"> </script>

2. Javascript code

Copy codeThe Code is as follows:
<Script type = "text/javascript">
$ (Function (){
$ ('Input: text: first '). focus ();
Var $ indium = $ ('input: text ');
$ Indium. bind ('keylow', function (e ){
Var key = e. which;
If (key = 13 ){
E. preventDefault ();
Var nxtIdx = $ indium. index (this) + 1;
$ (": Input: text: eq (" + nxtIdx + ")"). focus ();
}
});
});
</Script>

Analysis:
$ ('Input: text: first '). focus ();

When the page is initialized, focus on the first text box

Var $ indium = $ ('input: text ');

Type = set of elements in the text box

$ Indium. bind ('keylow', function (e ){}

Bind the 'keylow' event to the text box collection

Var key = e. which;

Take the currently pressed key value, for example, Enter key value = 13

E. preventDefault ();

It can prevent other things from happening due to its default behavior. Here we organize PostBack, but switch the focus. Another similar method is stopPropagation, which can prevent js event bubbling.

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.