How to Set Active Tab in jQuery Ui

后端 未结 9 1361
灰色年华
灰色年华 2020-12-08 18:51

Can you please let me know how I can set the active tab in jquery ui with a button click out of the tabs?

I have a button like:



        
相关标签:
9条回答
  • 2020-12-08 19:12

    I know this is an old question. But I think the way to change the selected tab have changed slight

    The way to change the active tab now is by giving active the index of the tab. Note the index starts at 0 not 1. To make the second tab active you will use the the index 1.

    //this will select your first tab
    $( "#tabs" ).tabs({ active: 0 });
    
    0 讨论(0)
  • 2020-12-08 19:12

    You can use this:

    $(document).ready(function() {
        $("#tabs").tabs();
        $('#action').click(function() {
            var selected = $("#tabs").tabs("option", "selected");
            $("#tabs").tabs("option", "selected", selected + 1);
        });
    });
    

    Also consider changing the input type as button instead of submit unless you want to submit the page.

    0 讨论(0)
  • 2020-12-08 19:12

    HTML: First you have o save the post tab index

    <input type="hidden" name="hddIndiceTab" id="hddIndiceTab" value="<?php echo filter_input(INPUT_POST, 'hddIndiceTab');?>"/>
    

    JS

    $( "#tabs" ).tabs({
        active: $('#hddIndiceTab').val(), // activate the last tab selected
        activate: function( event, ui ) {
            $('#hddIndiceTab').val($( "#tabs" ).tabs( "option", "active" )); // save the tab index in the input hidden element
        }
    });
    
    0 讨论(0)
提交回复
热议问题