Bootstrap Tabs: Next & Previous Buttons for Forms

后端 未结 3 1096
半阙折子戏
半阙折子戏 2020-12-08 02:10

I am trying to (eventually) split a form over several Bootstrap 3.x tabs, but I am having trouble with the previous and next buttons. Only the first next button functions an

3条回答
  •  死守一世寂寞
    2020-12-08 03:07

    Anyone who want to perform next previous operations on tab, follow following steps:

    a) Put next prev buttons in each tab-panel

    b) Bind the buttons clicks to body so that it will be called on click

    c) On click trigger click of next/prev tab

    d) If it is last tab redirect user to appropriate tab (Call show events of first or last tab)

    /**** JQuery *******/
    jQuery('body').on('click','.next-tab', function(){
          var next = jQuery('.nav-tabs > .active').next('li');
          if(next.length){
            next.find('a').trigger('click');
          }else{
            jQuery('#myTabs a:first').tab('show');
          }
    });
    
    jQuery('body').on('click','.previous-tab', function(){
          var prev = jQuery('.nav-tabs > .active').prev('li')
          if(prev.length){
            prev.find('a').trigger('click');
          }else{
            jQuery('#myTabs a:last').tab('show');
          }
    });
    /******* CSS *********/
    .previous-tab,
    .next-tab{
    	display: inline-block;
    	border: 1px solid #444348;
    	border-radius: 3px;
    	margin: 5px;
    	color: #444348;
    	font-size: 14px;
    	padding: 10px 15px;
    	cursor: pointer;
    }
    
    
    
    
    
    
    

    tab1 content

    //Include next prev buttons in the tab-content

    previous next

    tab2 content

    //Include next prev buttons in the tab-content

    previous next

提交回复
热议问题