Manually activate tabs jquery ui 1.10.3

2019-02-25 11:14发布

I am really getting mad, I searched through jquery ui doc and stackoverflow's questions (tons of questions) but I cannot figure out how to manually activate tabs ( .tabs() ) in jquery 1.10+ .

I founded and tried this solution :

$(mytabs).tabs("option", "active", index);

but it does not seem to work out. Can someone help me to know how to activate a tab , e.g. when I create a new one?

I can't figure out how jQuery UI has no longer the select event that , as I could know, accomplished this goal.

I'm creating new tabs with this function :

var addTab = function() {
  var tabTemplate = "<li><a href='#tabs-1'>non titolato</a></li>";
  var li = $.parseHTML(tabTemplate);
    $(li).addClass('ui-corner-all');
    $(".ui-tabs-nav").append(li);
    $("#stepBuilder").tabs('refresh');
}

I would like to activate the last one that was created.

1条回答
狗以群分
2楼-- · 2019-02-25 11:24

Use the following to activate the last tab.

$("#stepBuilder").tabs({ active: -1 });

I've created an example for you on jsfiddle.net.

The API doc says about the activate option:

active

Type: Boolean or Integer Default: 0

Which panel is currently open.

Multiple types supported:

Boolean: Setting active to false will collapse all panels. This requires the collapsible option to be true.

Integer: The zero-based index of the panel that is active (open). A negative value selects panels going backward from the last panel.

查看更多
登录 后发表回答