jQuery UI API - Tabs Widget
Category
Usage
**Description:** A single content area with multiple panels, each associated with a title in a list.
**Version added:** 1.0
Tabs are often used to divide content into sections to save space, just like an accordion.
Tabs require a specific set of markup to work correctly:
- Tabs must be in an ordered (
) or unordered () list - The "title" of each tab must be inside a list item (
) and must be wrapped in an anchor with thehrefattribute (). - Each tab panel can be any valid element, but it must have an id that corresponds to the hash in the associated tab's anchor.
The content of each tab panel can be defined in the page or loaded via Ajax. Both approaches are handled automatically based on the anchor associated with the tab's href . By default, tabs are activated on click, but this can be changed or overridden through the event option.
Here is some sample markup:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Keyboard interaction
When focus is on a tab, the following keyboard commands are available:
- UP/LEFT: Moves focus to the previous tab. If on the first tab, moves focus to the last tab. Activates the focused tab after a short delay.
- DOWN/RIGHT: Moves focus to the next tab. If on the last tab, moves focus to the first tab. Activates the focused tab after a short delay.
- HOME: Moves focus to the first tab. Activates the focused tab after a short delay.
- END: Moves focus to the last tab. Activates the focused tab after a short delay.
- SPACE: Activates the panel associated with the focused tab.
- ENTER: Activates or toggles the panel associated with the focused tab.
- ALT+PAGE UP: Moves focus to the previous tab and activates it immediately.
- ALT+PAGE DOWN: Moves focus to the next tab and activates it immediately.
When focus is on a panel, the following keyboard commands are available:
- CTRL+UP: Moves focus to the associated tab.
- ALT+PAGE UP: Moves focus to the previous tab and activates it immediately.
- ALT+PAGE DOWN: Moves focus to the next tab and activates it immediately.
Theming
The Tabs Widget uses jQuery UI CSS Framework to define the styles for its look and feel. To use the styles specific to tabs, you can use the following CSS class names:
ui-tabs: The outer container of the tabs. When thecollapsibleoption is set, this element will additionally have aui-tabs-collapsibleclass。ui-tabs-nav: The tab list.- The active list item in the navigation has a
ui-tabs-activeclass. A list item whose content is loaded via an Ajax call has aui-tabs-loadingclass。ui-tabs-anchor: The anchor used to switch panels.
- The active list item in the navigation has a
ui-tabs-panel: The panel associated with a tab. Visible only when its corresponding tab is active.
- The active list item in the navigation has a
ui-tabs-activeclass. A list item whose content is loaded via an Ajax call has aui-tabs-loadingclass。ui-tabs-anchor: The anchor used to switch panels.
ui-tabs-anchor: The anchor used to switch panels.
ui-tabs-panel: The panel associated with a tab. Visible only when its corresponding tab is active.
Depends on
- UI Core
- Widget Factory
- Effects Core(optional; when used with the
showandhideoption)
Additional Notes
- This widget requires some functional CSS; otherwise it will not work. If you create a custom theme, use the widget-specific CSS file as a starting point.
Example
A simple jQuery UI Tabs.
标签页部件(Tabs Widget)演示
第一个标签是默认激活的:
$( "#tabs" ).tabs();
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.