如何根据元素是否可见(在可查看区域中)更改元素的tabindex?我要执行以下操作之一:在进入新部分时重置当前tabindex,并将新的tabindex分配给该部分中的元素。或者能够禁用和重新启用某些元素的tabindex

的HTML:

    <div id="nav">
        <a id="firstLink" href="#section1" tabindex="1">Go to section 1</a>
        <a id="secondLink" href="#section2" tabindex="2">Go to section 2</a>
    </div>
    <div id="container">
        <div id="section1">
            <a href="#" tabindex="3">Specific to section 1</a>
        </div>
        <div id="section2">
            <a href="#" tabindex="3">Specific to section 2</a>
        </div>
    </div>

我只希望链接在其部分可见时才处于制表顺序。

CSS:
    #container{
        overflow: hidden;
        width: 400px;
        height: 400px;
    }

    #section1{
        background: red;
        width: 400px;
        height: 400px;
    }

    #section2{
        background: green;
        width: 400px;
        height: 400px;
    }

实时示例:http://jsfiddle.net/2UF3n/5/

最佳答案

您可以从任何隐藏字段中动态添加或删除disabled="disabled",以使其tabindex值被忽略。

$("a:hidden").attr("disabled","disabled");

08-15 16:39
查看更多