Form submit should stay on the same tab

后端 未结 2 1501

On submitting the form by clicking a button, upon page reload same tab should be opened, but it is going to default tab. I have tried local storage but it doesn

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-28 18:30

    This got me working:

    $(document).ready(function() {
           var activeTab = localStorage.getItem('activeTab');
           if(activeTab){
           $('.tab-links a[href="' + activeTab + '"]').tab('show');
           }
    $('.tabs .tab-links a').on('click', function(e)  {
                var currentAttrValue = jQuery(this).attr('href');
                localStorage.setItem('activeTab', currentAttrValue);
                jQuery('.tabs ' + currentAttrValue).siblings().slideUp(400);
                jQuery('.tabs ' + currentAttrValue).delay(400).slideDown(400);  
                jQuery(this).parent('li').addClass('active').siblings().removeClass('active');       
                e.preventDefault();
                });
    });
    

提交回复
热议问题