Focus on Table row TR for accessiblity

2019-07-27 05:24发布

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.

2条回答
贪生不怕死
2楼-- · 2019-07-27 05:35

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()

查看更多
三岁会撩人
3楼-- · 2019-07-27 05:46

You can focus on elements that are ordinarily unfocusable by assigning a tabindex:

<td tabindex="1">focus on me</td>
查看更多
登录 后发表回答