2012-09-28 62 views
0

下一個元素爲什麼這個不行焦點與「tabindex屬性」,但在接下來的TD

我試圖把重點放在下一個元素與「tabindex屬性」未來TD。

我的要素不具有ID和所有具有相同的tabIndex

$('form').keypress(function (event) { 

     $(":focus").parents('td').next('td').find('[tabindex]:first').focus(); //this is not working 

    } 

}); 


<table> 
    <tr> 
     <td><input name="TextBox1" type="text" tabindex="1" /></td> 
     <td><input name="TextBox2" type="text" tabindex="1" /></td> 
    </tr> 
    <tr> 
     <td><input name="TextBox3" type="text" tabindex="1" /></td> 
     <td><input name="TextBox5" type="text" tabindex="1" /></td> 
    </tr> 
    <tr> 
     <td> 
       <select name="DropDownList1" tabindex="1"> 
        <option value=""></option> 
        <option value=""></option> 
        <option value=""></option> 
        <option value=""></option> 
        <option value=""></option> 
       </select> 
     </td> 
     <td><input name="TextBox6" type="text" tabindex="1" /></td></td> 
    </tr> 
    <tr> 
     <td><input name="TextBox7" type="text" tabindex="1" /></td></td> 
     <td><input name="TextBox8" type="text" tabindex="1" /></td></td> 
    </tr> 

</table> 
+0

爲什麼你有tabindex 1的一切? – hsalama

回答

2

我修改你的代碼jsfiddle

$('form').keypress(function (event) { 

     $(":focus").parents('td').next('td').find('[tabindex="1"]:first').focus(); //this is not working 



}); 
​ 
+0

非常感謝 - 但我看到它不會跳到下一個tr中的下一個t - 任何想法?謝謝 –

+0

它跳躍檢查jsfiddle。但如果你想要在下一個td中輸入文本,請使用keydown代替按鍵。 – Anoop

+0

謝謝我檢查,但在我的行它停止在第二個TD。你知道如何讓它跳到下一行的第一個輸入 –

0

試試這個

$('#Id:focus').find('input[tabindex=1]').focus() 

和索引你的tabIndex