<Script type = "text/javascript" src = "jquery-1.4.4.min.js"> </script>
<Script type = "text/javascript">
$ (Function (){
Var length = $ (": input"). length;
$ (": Input"). keyup (function (e ){
Var key = e. which;
If (13 = key ){
Var index = $ (": input"). index (this );
Var newIndex = index + 1;
If (length = newIndex)
{
NewIndex = 0;
}
$ (": Input: eq (" + newIndex + ")"). focus ();
}
});
});
</Script>
</Head>
<Body>
<Form id = "frm1">
<Input type = "text"/> <br/>
<Input type = "text"/> <br/>
<Select>
<Option> option 1 </option>
<Option> option 2 </option>
</Select>
<Br/>
<Input id = "btn" type = "button" value = "Submit"/>
</Form>
</Body>
Notes
① $ (": Input") indicates all controls in the form. Unlike $ ("input"), only the input tag is obtained, and select is not obtained.
② The index function is a useful function in jQuery.
However, in actual situations, we do not have to cyclically obtain the focus. When the submit button gets the focus, we submit the form.
$ (Function (){
$ (": Input"). keyup (function (e ){
Var key = e. which;
If (13 = key ){
Var index = $ (": input"). index (this );
Var newIndex = index + 1;
$ (": Input: eq (" + newIndex + ")"). focus ();
}
});
$ ("# Btn"). click (function (){
$ ("Frm1"). submit ();
});
});
From IT fat Column