如何在jquery-ui 1.9中以编程方式更改选项卡?

如何使用jquery-ui 1.9以编程方式更改选项卡?

注意:发布答案是因为我花了4次以上的搜索才能在stackoverflow上找到正确的答案。 它出现在1.9中,API已更改,在早期版本中,您将使用$("#tabs").tabs("select", 2)

  $(document).ready(function() { $("#tabs").tabs(); // assume you want to change to the 3rd tab after 3 seconds setTimeout(function() { // ??? }, 3000); });  

Container 1

Container 2

Container 3

select方法自1.9以来不推荐使用 ,并在1.10中删除 。 请改用active选项。

示例( jsfiddle也提供):

  

Container 1

Container 2

Container 3

根据id的选择是非常直接的,正如Sonjz在上面指出的那样…但根据tabId的选择比较棘手……我只是想分享它以防任何人需要

 var index = $('#tabs a[href="#tab_id"]').parent().index(); $("#tabs").tabs("option", "active", index); 

试试这个

 $('#tabs a[href="#tabs-2"]').tab('show') 

这里#tabs-2表示要切换的选项卡。

谢谢。