2

Is it possible to add class if user jumps in to specific tabindex? I want add class when user tab reaches at specific index and remove class when jumps into another? Thanks!

here i want to add active class when tab focuses at tabindex=3:

<input type="text" tabindex="1" />
<input type="text" tabindex="2" />
<a href="#" tabindex="3" />Hello</a>
<input type="text" tabindex="4" />

here is fiddle for test: http://jsfiddle.net/4XbN3/

4

1 回答 1

4

使用正确的 tabindex 定位元素,并在 focus 上添加一个类:

$('[tabindex="3"]').on('focus', function() {
    $(this).addClass('active');
});

小提琴

如果您需要删除该类,那么在模糊上也是一样的:

$('[tabindex="3"]').on({
    focus: function() {
        $(this).addClass('active');
    },
    blur: function() {
        $(this).removeClass('active');
    }
});
于 2013-07-18T20:37:47.853 回答