How to open specific tab of bootstrap nav tabs on click of a particuler link using jQuery?

前端 未结 8 2090
Happy的楠姐
Happy的楠姐 2020-11-29 01:32

I am new to jquery and bootstrap,so please consider my mistakes.I have created a bootstrap modal for login and registration. It contains two nav-tabs called as login and reg

相关标签:
8条回答
  • 2020-11-29 02:29

    HTML:

    <a href="PageName.php#tabID">link to other page tab</a>
    

    Javascript:

    window.onload = function(){  
    
        var url = document.location.toString();
        if (url.match('#')) {
            $('.nav-tabs a[href="#' + url.split('#')[1] + '"]').tab('show');
        }
    
        //Change hash for page-reload
        $('.nav-tabs a[href="#' + url.split('#')[1] + '"]').on('shown', function (e) {
            window.location.hash = e.target.hash;
        }); 
    } 
    
    0 讨论(0)
  • 2020-11-29 02:32

    You may access through tab Id as well, But that id is unique for same page. Here is an example for same

    $('#product_detail').tab('show');
    

    In above example #product_details is nav tab id

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