Set default tab in jQuery UI Tabs

前端 未结 4 1620
眼角桃花
眼角桃花 2020-12-05 12:52

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 t

相关标签:
4条回答
  • 2020-12-05 13:26

    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 });
    
    0 讨论(0)
  • 2020-12-05 13:31

    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

    0 讨论(0)
  • 2020-12-05 13:40

    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.

    0 讨论(0)
  • 2020-12-05 13:45

    Pay attention that in jQuery UI 1.9 selected changed to active option.
    jQuery UI Documentation (Tabs)

    0 讨论(0)
提交回复
热议问题