在 jQuery UI 选项卡中设置默认选项卡
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4565128/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set default tab in jQuery UI Tabs
提问by Christopher
I have a monthly calendar with just basic HTML tables, with each month in a jQuery UI tabs tab. How can I change which jQuery UI tab is loaded by default? I want to keep the months in order in the navigation, but have the current month show on page load.
我有一个只有基本 HTML 表格的月历,每个月都在一个 jQuery UI 选项卡选项卡中。如何更改默认加载的 jQuery UI 选项卡?我想在导航中按顺序排列月份,但在页面加载时显示当前月份。
回答by redreinard
Please note that this option got renamed in jqueryui 1.9, it is now called "active" (hope this saves someone else the headache I just went through):
请注意,此选项在 jqueryui 1.9 中被重命名,现在称为“活动”(希望这可以为其他人省去我刚刚经历的头痛):
$('#tabid').tabs({
active: index
});
or
或者
$('#tabid').tabs("option", "active", index);
回答by Rion Williams
Update
更新
The API has changed since my original answer and the release of jQuery 1.9. The preferred approach is to use the active
option as mentioned in redreinard's answer:
自从我的原始答案和 jQuery 1.9 发布以来,API 发生了变化。首选方法是使用redreinard 的回答中active
提到的选项:
$('selector').tabs({ active: index });
Older Approach (pre jQuery 1.9)
旧方法(jQuery 1.9 之前)
According to the documentation on the JqueryUI Tabs, you could set this by using the available select
function as seen in either the approaches below :
根据JqueryUI Tabs 上的文档,您可以使用可用select
函数进行设置,如下面的任一方法所示:
// index will be the index of the tab that you wish to select
$('selector').tabs( "select" , index )
$('selector').tabs({ selected: index });
回答by Jenka1980
Pay attention that in jQuery UI 1.9 selected changed to active option.
jQuery UI Documentation (Tabs)
请注意,在 jQuery UI 1.9 中选择更改为活动选项。
jQuery UI 文档(选项卡)
回答by Tony Miller
You want the selected optionof the tabs. Note that there's also a cookie optionso that people leaving and returning to your page will have the same tab opened as when they left.
您需要选项卡的选定选项。请注意,还有一个 cookie 选项,以便人们离开和返回您的页面时会打开与离开时相同的选项卡。