【问题标题】:Set Html-Tabindex back to "auto"将 Html-Tabindex 设置回“自动”
【发布时间】:2014-01-10 09:29:36
【问题描述】:

在包含许多表单字段的页面上,我想将特定字段设置为 tabindex="-1"。但是当用户选中一个复选框时,tabindex="-1" 的字段应该像往常一样被表格访问。 这该怎么做? Tabindex="auto" & tabindex="" 不起作用。

我的 Javascript:

function setTabindex(checkboxChecked) {
    var tabindexValue = cbChecked ? '' /* <-- what should I enter here? */ : '-1';
    var noTabindexElements = document.querySelectorAll('input[data-notabindex]');

    for (var i = 0; i < noTabindexElements.length; i++) {
        noTabindexElements[i].setAttribute('tabindex', tabindexValue);
    }
}

【问题讨论】:

    标签: javascript html tabindex


    【解决方案1】:

    根据MDN & HTML specs 这应该可以,但我还没有测试过:

    function setTabindex(checkboxChecked) {
        var tabindexValue = cbChecked ? 0 : -1;
        var noTabindexElements = document.querySelectorAll('input[data-notabindex]');
    
        for (var i = 0; i < noTabindexElements.length; i++) {
            noTabindexElements[i].tabIndex = tabindexValue;
        }
    }
    

    【讨论】:

      【解决方案2】:

      对于所有正在寻找更好的东西的人,您也可以这样做:

      input.setAttribute("tabindex", null);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-05-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-13
        • 2011-10-10
        • 2019-10-01
        相关资源
        最近更新 更多