Bootstrap 3选项卡,firefox自动对焦无法正常工作

时间:2015-05-08 09:30:38

标签: javascript twitter-bootstrap firefox

我正在使用bootstrap 3标签。要直接跳转到特定选项卡,我使用以下代码:

function tabNavigation() {
    if (location.hash.indexOf("#tab_") == 0 && $('a[href="' + location.hash + '"]').length) {
      var $d = $('a[href="' + location.hash + '"]');
    }
    else {
      $d = $(".tabnavigation a:first");
    }
    $d.tab('show');
    $(location.hash + " [autofocus]").first().focus();
  }

  window.addEventListener("hashchange", tabNavigation, false);
  tabNavigation();
  $("body").on("click", ".tabnavigation a", function () {
    window.location.hash = $(this).attr("href").substr(1);
  });
});

这可以按预期工作。现在的问题是,如果其中一个选项卡上有自动对焦属性,它在Firefox中无效(但在Chrome中可以使用)。

<input class="form-control" autofocus id="input2" required="required" name="input2" type="text">

我也试过用js:

$("[autofocus]").first().focus();

看一下bootplay(适用于Chrome,但不适用于Firefox):

http://www.bootply.com/iN1e0QTVif

但这既不起作用。有什么想法吗?

0 个答案:

没有答案
相关问题