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.