HTML
<dialog>
element
represents a dialog box or other interactive component, such as a dismissable alert, inspector, or subwindow.
| 内容类别 | 流内容 , 区间根 |
|---|---|
| 准许内容 | 流内容 |
| Tag omission | None, both the starting and ending tag are mandatory. |
| Permitted parents | Any element that accepts flow content |
| Implicit ARIA role | dialog |
| Permitted ARIA roles |
alertdialog
|
| DOM 接口 |
HTMLDialogElement
|
此元素包括 全局属性 .
tabindex
attribute must not be used on the
<dialog>
元素。
open
open
attribute is not set, the dialog
shouldn't
be shown to the user.
<form>
elements can close a dialog if they have the attribute
method="dialog"
. When such a form is submitted, the dialog closes with its
returnValue
property set to the
value
of the button that was used to submit the form.
::backdrop
CSS pseudo-element can be used to style behind a
<dialog>
element when the dialog is displayed with
HTMLDialogElement.showModal()
. For example, to dim unreachable content behind the modal dialog.
<dialog open> <p>Greetings, one and all!</p> </dialog>
This example opens a pop-up dialog box that contains a form, when the "Update details" button is clicked.
<!-- Simple pop-up dialog box containing a form -->
<dialog id="favDialog">
<form method="dialog">
<p><label>Favorite animal:
<select>
<option></option>
<option>Brine shrimp</option>
<option>Red panda</option>
<option>Spider monkey</option>
</select>
</label></p>
<menu>
<button value="cancel">Cancel</button>
<button id="confirmBtn" value="default">Confirm</button>
</menu>
</form>
</dialog>
<menu>
<button id="updateDetails">Update details</button>
</menu>
<output aria-live="polite"></output>
var updateButton = document.getElementById('updateDetails');
var favDialog = document.getElementById('favDialog');
var outputBox = document.querySelector('output');
var selectEl = document.querySelector('select');
var confirmBtn = document.getElementById('confirmBtn');
// "Update details" button opens the <dialog> modally
updateButton.addEventListener('click', function onOpen() {
if (typeof favDialog.showModal === "function") {
favDialog.showModal();
} else {
alert("The <dialog> API is not supported by this browser");
}
});
// "Favorite animal" input sets the value of the submit button
selectEl.addEventListener('change', function onSelect(e) {
confirmBtn.value = selectEl.value;
});
// "Confirm" button of form triggers "close" on dialog because of [method="dialog"]
favDialog.addEventListener('close', function onClose() {
outputBox.value = favDialog.returnValue + " button clicked - " + (new Date()).toString();
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of '<dialog>' in that specification. |
实时标准 | |
|
HTML 5.2
The definition of '<dialog>' in that specification. |
推荐 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
dialog
|
Chrome 完整支持 37 | Edge 完整支持 79 |
Firefox
完整支持
53
注意事项
Disabled
|
IE 不支持 No | Opera 完整支持 24 | Safari 不支持 No | WebView Android 完整支持 37 | Chrome Android 完整支持 37 |
Firefox Android
完整支持
53
注意事项
Disabled
|
Opera Android 完整支持 24 | Safari iOS 不支持 No | Samsung Internet Android 完整支持 3.0 |
open
|
Chrome 完整支持 37 | Edge 完整支持 79 |
Firefox
完整支持
53
注意事项
Disabled
|
IE 不支持 No | Opera 完整支持 24 | Safari 不支持 No | WebView Android 完整支持 37 | Chrome Android 完整支持 37 |
Firefox Android
完整支持
53
注意事项
Disabled
|
Opera Android 完整支持 24 | Safari iOS 不支持 No | Samsung Internet Android 完整支持 3.0 |
完整支持
不支持
见实现注意事项。
用户必须明确启用此特征。
Include this polyfill to provide support for browsers without
<dialog>
元素。
close
event
cancel
event
::backdrop
pseudo-element