jQuery UI API - Menu Widget
Category
Usage
**Description:** A themeable menu for navigation with mouse and keyboard interaction.
**Version added:** 1.9
A menu can be created with any valid markup as long as the elements have a strict parent/child relationship and each item has an anchor. The most commonly used element is an unordered list ():
If you use a non- / structure, using the same element for the menu and menu items, use the menus option to distinguish the two elements, e.g. menus: "div.menuElement"。
Any menu item can be disabled by adding a ui-state-disabled class to the element.
Icon
To add icons to the menu, include the icons in the markup:
The Menu automatically adds the necessary padding to items without icons.
Separators
A separator element can be created by including an unlinked menu item whose content is only spaces/dashes:
Keyboard interaction
- ENTER/SPACE: Invoke the action of the focused menu item, which may open a submenu.
- UP: Move focus to the previous menu item.
- DOWN: Move focus to the next menu item.
- RIGHT: If available, open the submenu.
- LEFT: Close the current submenu and move focus to the parent menu item. If focus is not on a submenu, do nothing.
- ESCAPE: Close the current submenu and move focus to the parent menu item. If focus is not on a submenu, do nothing.
Typing a letter moves focus to the first item whose text starts with that letter. Repeating the same character cycles through matching items. Typing more characters within a short time matches the string typed.
Disabled items can receive keyboard focus but do not allow any interaction.
Theming
The Menu Widget uses jQuery UI CSS Framework to define the style of its look and feel. To use menu-specific styling, you can use the following CSS class names:
ui-menu: The outer container of the menu. If the menu contains icons, this element additionally has aui-menu-iconsclass。ui-menu-item: The container for an individual menu item.ui-menu-icon: Throughiconsoption for submenu icon settings.
ui-menu-divider: The separator element between menu items.
ui-menu-icon: Throughiconsoption for submenu icon settings.
ui-menu-divider: The separator element between menu items.
Depends on
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 menu.
菜单部件(Menu Widget)演示