如何将标签从一个元素聚焦到另一个元素?

时间:2011-10-17 05:03:24

标签: javascript jquery html

我有一个表格,其中以下是其中一个表格

<tr>
   <td>&nbsp;</td>
   <td valign="top"><nobr> Address Line 1 :</nobr></td>
   <td><input type="text" name="strLine1" class="textfield" id="strLine1" onFocus="nextfield ='strLine2';" />
<br /><span id="strLine1Info" ></span>              
   </td>
   <td>&nbsp;</td>
   <td align="left" valign="top"><nobr>Address Line 1 :</nobr></td>
   <td><input type="text" name="hstrLine1" class="textfield" id="hstrLine1" onFocus="nextfield ='hstrLine2';" />
    <br /><span id="hstrLine1Info" ></span>             
   </td>
   <td>&nbsp;</td>
 </tr>
 <tr>
   <td>&nbsp;</td>
   <td valign="top"><nobr>Address Line 2 :</nobr></td>
   <td><input type="text" name="strLine2" class="textfield" id="strLine2" onFocus="nextfield ='city';" />
    <br /><span id="strLine2Info" ></span>              
   </td>
   <td>&nbsp;</td>
   <td align="left" valign="top"><nobr>Address Line 2 :</nobr></td>
   <td><input type="text" name="hstrLine2" class="textfield" id="hstrLine2" onFocus="nextfield ='hcity';" />
    <br /><span id="hstrLine2Info" ></span>             
   </td>
    <td>&nbsp;</td>
 </tr>
 <tr>
     <td>&nbsp;</td>
     <td valign="top"> State :</td>
     <td>
    <input type="text" name="state" class="textfield" value="Secrete" id="state"  onFocus="nextfield ='Zip';" disabled />
    <br /><span id="stateInfo" ></span>                         </td>
     <td>&nbsp;</td>
     <td valign="top"> State :</td>
     <td>
<input type="text" name="hstate" class="textfield" value="Secrete" id="hstate" onFocus="nextfield ='hZip';" disabled />
<br /><span id="hstateInfo" ></span>                            </td>
     <td>&nbsp;</td>
   </tr>

我想从

移动标签(键盘标签)
Address Line 1 -> 
Address Line 2 -> 
State -> (second column)
Address Line 1 -> (second column)
Address Line 2 -> (second column)State

我想在jQuery中执行此操作。

2 个答案:

答案 0 :(得分:4)

逐个使用每个元素的tabindex属性。对于第一列的选项卡索引,依次为第二列的选项卡索引。

答案 1 :(得分:2)

为什么不在订单中的每个表单元素上设置tabindex值?