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

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

    Hi Try this one folks!

    $('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
      // save current clicked tab in local storage does not work in Stacksnippets
      // localStorage.setItem('lastActiveTab', $(this).attr('href'));
    });
    //get last active tab from local storage
    var lastTab = "#profile"; // localStorage.getItem('lastActiveTab');
    console.log(lastTab + "tab was last active")
    if (lastTab) {
      $('[href="' + lastTab + '"]').tab('show');
    }
    
    
    
    
    
    Home
    Profile
    Message
    Settings

提交回复
热议问题