Set active tab by clicking a link thats outside of the tabs?

狂风中的少年 提交于 2020-01-01 16:42:08

问题


Im using the jQuery UI Tabs: http://api.jqueryui.com/tabs/

How can I make a link on my page thats outside of the tabs, when clicked make a certain tab active? Thanks


回答1:


See http://api.jqueryui.com/tabs/#option-active

To get current active tab index:

var currentActive = $( ".selector" ).tabs( "option", "active" );

To set current active tab:

$( ".selector" ).tabs( "option", "active", <number of tab> );

For example:

$('a').click(function(){
         $( ".tabs" ).tabs( "option", "active", 2 );
});



回答2:


In IE10 option 'active' not work. I use instead of 'active' option 'selected'.

$( ".selector" ).tabs( "option", "selected", <number of tab> );



回答3:


Ive marked @Secator's answer as correct as I can see from the documentation hes right. However for some reason it didnt work for me so instead I 'manually' simulated a click on the tab:

        $("#myTrigger").click(function(e) {
              $("#id-of-normal-tab-link").click();
              e.preventDefault(); //prevent default behavior of the a#myTrigger 
        });



回答4:


$( "#tabs" ).tabs({ active: tabNumber });

tabNumber starts with 0




回答5:


Try this:

<li ....> 
     <a href="#tab-number">Tab Title</a>
</li> 

and them your url look like this: "[URL]#tab-number"

I hope help you.... Regards...



来源:https://stackoverflow.com/questions/15641134/set-active-tab-by-clicking-a-link-thats-outside-of-the-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!