JavaScript jump to Next control _javascript tips

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" > <ptml> <pead> & Lt;meta http-equiv= "Content-type" content= "text/html; Charset=iso-8859-1 > <title> Press ENTER to jump to next control </title> <script language= "JavaScript" type= text/ JavaScript > var elemtype;//select the control type var elemobj; Select the Control object function Enterkey () {//Get all controls on the page var elems = document.forms[0].elements; var len=elems.length; Set return key jump control type var elemtypeary =["text", "textarea", "Select-one", "button", "Radio", "checkbox"]; var elemtypestr=elemtypeary.join (""); for (Var i=0;i<len;i++) {//Get control type Elemtype=elems[i].type; If the type control in the list is registered for its event if (Elemtypestr.indexof (elemtype)!=-1) {//The control has the focus after it has been assigned the value of the global variable Elems[i].onfocus=function () {// If the current button is typebtn, it is not registered onfocus event if (this.id== "Typebtnid") return; Gets the current control type Elemtype=this.type; Gets the current control object elemobj=this; //If the key is enter, change to tab to jump to the next control elems[i].onkeydown=function () {if (event.keycode==13) event.keycode=9}; }}//ExplicitShows the currently selected control type function GetType () {alert (elemtype); The focus is reset to the previous control Elemobj.focus () by clicking the button and then the button gets the focus; </script> </pead> <body> <form id= "Testform" > <!--registering events for page controls--> <input type= "but Ton "name=" querybtn "value= querybtn" onclick= "Enterkey ()" > <!--Get page control type--> <input type= "button" name= "Ty Pebtn "id=" Typebtnid "value=" typebtn "onclick=" GetType () "> <select id=" sel "> <option value=" 1 ">123&lt ;/option> <option value= "2" >456</option> </select> <input type= "text" id= "a" > <input typ E= "text" id= "B" > <input type= "text" id= "C" > <textarea rows= "5" cols= "" id= "Taid" ></textarea> <input type= "Radio" name= "Radiongroup" id= "ARd" > <input type= "Radio" name= "Radiongroup" id= "BRD" > < Input type= "checkbox" id= "ACb" > </form> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Related Article

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.