Linking to a Bootstrap Tab from outside - how to set the tab to “active”?

前端 未结 7 1183
清歌不尽
清歌不尽 2020-12-01 17:10

I have a Bootstrap \"tab\" navigation with 3 different content tabs. It works perfectly except that I want to link to one of the tabs from OUTSIDE the tab navigation. Meanin

7条回答
  •  难免孤独
    2020-12-01 17:43

    You can do a small trick to achieve this:

    $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
        var target = this.href.split('#');
        $('.nav a').filter('[href="#'+target[1]+'"]').tab('show');
    })
    

    http://jsfiddle.net/s6bP9/

提交回复
热议问题