Set default tab in jQuery UI Tabs
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 i开发者_StackOverflow社区s loaded by default? I want to keep the months in order in the navigation, but have the current month show on page load.
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):
$('#tabid').tabs({
active: index
});
or
$('#tabid').tabs("option", "active", index);
See: http://api.jqueryui.com/tabs/#option-active
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:
$('selector').tabs({ active: index });
Older Approach (pre 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 :
// index will be the index of the tab that you wish to select
$('selector').tabs( "select" , index )
$('selector').tabs({ selected: index });
Pay attention that in jQuery UI 1.9 selected changed to active option.
jQuery UI Documentation (Tabs)
You want the selected option of the tabs. Note that there's also a cookie option so that people leaving and returning to your page will have the same tab opened as when they left.
精彩评论