Preventing tab to cycle through address bar

前端 未结 8 1375
一生所求
一生所求 2021-02-20 06:54

I realize this is probably an accessibility issue that may best be left alone, but I\'d like to figure out if it possible to prevent the tab from visiting the address bar in the

8条回答
  •  难免孤独
    2021-02-20 07:43

    I used m-albert solution and it works. But in my case I do not control the tabindex properties. My intention is set the focus on a toolbar at the top of the page (first control) when user leaves the last control on the page.

    $(':input:visible').last().on('keydown', function (e) {
        if (e.keyCode == 9 && e.shiftKey == false) {
            e.preventDefault();
            $('html, body').animate({
                scrollTop: 0
            }, 500);
            $(':input:visible', context).first().focus();
        }
    });
    

    Where context can be any Jquery object, selector, or even document, or you can omit it.

    The scrolling animation, of course, is optional.

提交回复
热议问题