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

前端 未结 8 2122
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:

    link to other page tab
    

    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;
        }); 
    } 
    

提交回复
热议问题