Bootstrap tab activation with JQuery

后端 未结 7 1253
花落未央
花落未央 2020-12-13 03:15

I have the following code

  • AAA
  • &
7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 03:52

    why not select active tab first then active the selected tab content ?
    1. Add class 'active' to the < li > element of tab first .
    2. then use set 'active' class to selected div.

        $(document).ready( function(){
            SelectTab(1); //or use other method  to set active class to tab
            ShowInitialTabContent();
    
        });
        function SelectTab(tabindex)
        {
            $('.nav-tabs li ').removeClass('active');
            $('.nav-tabs li').eq(tabindex).addClass('active'); 
            //tabindex start at 0 
        }
        function FindActiveDiv()
        {  
            var DivName = $('.nav-tabs .active a').attr('href');  
            return DivName;
        }
        function RemoveFocusNonActive()
        {
            $('.nav-tabs  a').not('.active').blur();  
            //to >  remove  :hover :focus;
        }
        function ShowInitialTabContent()
        {
            RemoveFocusNonActive();
            var DivName = FindActiveDiv();
            if (DivName)
            {
                $(DivName).addClass('active'); 
            } 
        }
    

提交回复
热议问题