2015-05-08 28 views
0

我正在使用引导程序3选项卡。要直接跳转到特定的选项卡,我使用以下代码:引导程序3选项卡,Firefox自动对焦不起作用

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

尝试'autofocus =“true”'在您的代码 –

+0

不,它不工作。你可以在bootply上试试它 – bernhardh

回答

相关问题