jQuery UI API - Tooltip Widget
Category
Usage
**Description:** A customizable, themeable tooltip that replaces the native tooltip.
**Version added:** 1.9
The tooltip replaces native tooltips, making them themeable and allowing for a variety of customizations:
- Display content beyond the title, such as inline footnotes or additional content retrieved via Ajax.
- Custom positioning, for example, centering the tooltip over the element.
- Add extra styles to customize the appearance of warning or error areas.
By default, a fading animation is used to show and hide the tooltip, which looks more polished than simply toggling visibility. This can be customized through the show and hide option.
items and content options need to be kept in sync. If you change one, you need to change the other as well.
In general, disabled elements do not trigger any DOM events. Therefore, it is not possible to properly control tooltips on disabled elements, since we need to listen for events to decide when to show and hide the tooltip. As a result, jQuery UI cannot guarantee any level of support for tooltips attached to disabled elements. This means that if you need tooltips on disabled elements, you may need to use a mix of native tooltips and jQuery UI tooltips.
Theming
The Tooltip Widget uses jQuery UI CSS Framework to define the styles for its look and feel. To use the styles specific to the tooltip, you can use the following CSS class names:
ui-tooltip: The outer container of the tooltip.ui-tooltip-content: The content of the tooltip.
Depends on
- UI Core
- Widget Factory
- Position
- 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
Creates a tooltip on the document using event delegation for all elements with a title attribute.
工具提示框部件(Tooltip Widget)演示