Go to Specific Tab on different Page link click and toggle active class

前端 未结 1 1667
醉梦人生
醉梦人生 2021-01-06 11:39

I\'m developing a web page in which I\'m using Twitter\'s Bootstrap Framework and their Bootstrap Tabs JS. It works great but I am trying to add extra links outside the tabs

相关标签:
1条回答
  • 2021-01-06 12:00

    You can use jQuery to get the page url #hash and select the Bootstrap tab...

    var hash = document.location.hash;
    if (hash) {
        $('.nav-tabs a[href='+hash+']').tab('show');
    } 
    
    // Change hash for page-reload
    $('.nav-tabs a').on('shown.bs.tab', function (e) {
        window.location.hash = e.target.hash;
    });
    

    Code: http://codeply.com/go/RypzN2UXKF

    Demo (select tab 2): http://codeply.com/render/RypzN2UXKF#tab2

    0 讨论(0)
提交回复
热议问题