jQuery UI API - Dialog Widget
Category
Usage
**Description:** Open content in an interactive overlay.
**Version added:** 1.0
A dialog is a floating window with a title bar and a content area. A dialog window can be moved, resized, and by default closed via the 'x' icon.
If the content exceeds the maximum height, a scrollbar appears automatically.
A bottom button bar and a semi-transparent modal overlay are common additions.
Focus
When a dialog is opened, focus automatically moves to the first item that meets the following conditions:
- With
autofocusThe first element within the dialog with an autofocus attribute - The first tabbable element within the dialog content
:tabbableElement - The first button within the dialog's button pane
:tabbableElement - The dialog's close button
- The dialog itself
When opened, the Dialog Widget ensures that focus cycles via Tab among elements inside the dialog, excluding elements outside it. Modal dialogs prevent mouse users from clicking elements outside the dialog.
When the dialog is closed, focus automatically returns to the element that had focus before the dialog was opened.
Hiding the close button
In some cases you may want to hide the close button, for example when there is already a close button in the button pane. The best solution is via CSS. As an example, you can define a simple rule like:
.no-close .ui-dialog-titlebar-close {
display: none;
}
Then you can add a no-close class to any dialog to hide its close button:
$( "#dialog" ).dialog({
dialogClass: "no-close",
buttons: [
{
text: "OK",
click: function() {
$( this ).dialog( "close" );
}
}
]
});
Theming
The Dialog Widget uses jQuery UI CSS Framework to define the style of its look and feel. To use dialog-specific styling, you can use the following CSS class names:
ui-dialog: The outer container of the dialog.ui-dialog-titlebar: The title bar containing the dialog's title and close button.ui-dialog-title: The container around the dialog's text title.ui-dialog-titlebar-close: The dialog's close button.
ui-dialog-content: The container around the dialog's content. This is also the element on which the widget is instantiated.ui-dialog-buttonpane: The panel containing the dialog's buttons. It is only present when thebuttonsoption is set.ui-dialog-buttonset: The container around the buttons.
ui-dialog-title: The container around the dialog's text title.ui-dialog-titlebar-close: The dialog's close button.
ui-dialog-content: The container around the dialog's content. This is also the element on which the widget is instantiated.ui-dialog-buttonpane: The panel containing the dialog's buttons. It is only present when thebuttonsoption is set.ui-dialog-buttonset: The container around the buttons.
In addition, when the modal option is set, an element with a ui-widget-overlay class name is appended to 。
Depends on
- UI Core
- Widget Factory
- Position
- Button Widget
- Draggable Widget (optional; when used with the
draggableoption) - Resizable Widget (optional; when used with the
resizableoption) - 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 dialog.
对话框部件(Dialog Widget)演示
我是一个对话框