Press enter to switch the focus, and press enter to switch the focus.

Source: Internet
Author: User

Press enter to switch the focus, and press enter to switch the focus.


When registering information online, you often enter a message and press Enter. The focus is automatically switched to the next input box. Today, the trainer just made a small example.


<Html> 

In the above Code, first obtain the DOM Node object of username, and then attach the keydown event to the DOM Node object of username, so that the event can capture the carriage return event. If the event is captured, switch the focus to the next input box.

In the method pointed to by the above keydown event, input the event object event

E = event? Event :( window. event? Window. event: null); this line solves the problem of browser compatibility.


In ie, the current event will be passed in to the event method. That is to say, in IE, this event will be passed in. In non-ie browsers, if no event is passed in, e will be equal to (window. event? Window. event: null) is window. event, which gets the event object of a non-IE browser.


Then, judge whether the keyCode of the event is 13 and the keyCode is 13, which indicates that the event is the Enter key. When you press the Enter key and enter a value in the input box, focus on the next input box.



In the above code, we can bind the event to the script part.Bind events to HTML elements, Declare the event processing method in script.

<Html> 

This method works the same way as above.


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.