Jquery UI - reload selected tab?

后端 未结 5 498
粉色の甜心
粉色の甜心 2021-02-04 17:30

Is there a way to reload the selected tab I know there is the .load() function. But it wants a tab index and I don\'t seem to see a way to grab the selected tabs id.

5条回答
  •  北海茫月
    2021-02-04 17:57

    Update: In jQuery 1.9, the selected option is renamed to active. See attomman's answer.

    To get the currently selected index, use the tabs('option','selected') function.

    E.g, if you have a button #button (and the #tabs element is made into tabs) where you want to get the index, do the following:

    $("#button").click(function() {
        var current_index = $("#tabs").tabs("option","selected");
    });
    

    Here's a demo: http://jsfiddle.net/sVgAT/


    To answer the question indicated by the title, in jQuery 1.8 and earlier, you would do:

    var current_index = $("#tabs").tabs("option","selected");
    $("#tabs").tabs('load',current_index);
    

    And in jQuery 1.9 and later, you would do:

    var current_index = $("#tabs").tabs("option","active");
    $("#tabs").tabs('load',current_index);
    

提交回复
热议问题