问题
I have a requirement to implement accessibility on table rows. The application should ideally be div based and rows should've been li's, but it is an old application and redesigning is not an option. So am forced to tweak and make it accessible. Could any one of you please help me to get focus on a table row? Is is possible at all?
For e.g: The table below, on tab, should first focus on the first row and then the input inside it. Again tabbing should do the same on the next row.
<table>
<tr>
<td><input type="textbox" /></td>
<td>some content</td>
<tr>
<tr>
<td><input type="textbox" /></td>
<td>some content</td>
<tr>
<tr>
<td><input type="textbox" /></td>
<td>some content</td>
<tr>
</table>
Any help is highly appreciated.
回答1:
I would do this (using jQuery) by $('tr').first().find('input').first().focus() , I did not know however Coomie's solution. I am not sure if his solution with html will work in IE. There are however some issues with focus() and limitation, if you decide to use this solution make sure you have read about jQuery focus()
回答2:
You can focus on elements that are ordinarily unfocusable by assigning a tabindex:
<td tabindex="1">focus on me</td>
来源:https://stackoverflow.com/questions/7103306/focus-on-table-row-tr-for-accessiblity