这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
returnValue
特性为
HTMLDialogElement
interface gets or sets the return value for the
<dialog>
, usually to indicate which button the user pressed to close it.
dialogInstance.returnValue = 'myReturnValue'; var myReturnValue = dialogInstance.returnValue;
A
DOMString
表示
returnValue
of the dialog.
The following example displays a button to open a
<dialog>
containing a form via the
showModal()
method. From there, either button will close the dialog.
<!-- Simple pop-up dialog box containing a form -->
<dialog id="favDialog">
<form method="dialog">
<p><label>Favorite animal:
<select name="favAnimal" required>
<option></option>
<option>Brine shrimp</option>
<option>Red panda</option>
<option>Spider monkey</option>
</select>
</label></p>
<menu>
<button>Cancel</button>
<button>Confirm</button>
</menu>
</form>
</dialog>
<menu>
<button id="updateDetails">Update details</button>
</menu>
<script>
(function() {
var updateButton = document.getElementById('updateDetails');
var dialog = document.getElementById('favDialog');
dialog.returnValue = 'favAnimal';
function openCheck(dialog) {
if (dialog.open) {
console.log('Dialog open');
} else {
console.log('Dialog closed');
}
}
function handleUserInput(returnValue) {
if (returnValue === 'Cancel' || returnValue == null) {
// User canceled the dialog, do nothing
} else if (returnValue === 'Confirm') {
// User chose a favorite animal, do something with it
}
}
// “Update details” button opens the <dialog> modally
updateButton.addEventListener('click', function() {
dialog.showModal();
openCheck(dialog);
handleUserInput(dialog.returnValue);
});
})();
</script>
注意 : You can find this example on GitHub as htmldialogelement-basic ( see it live also ).
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'returnvalue' in that specification. |
实时标准 | |
|
HTML 5.1
The definition of 'returnvalue' in that specification. |
推荐 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
returnValue
|
Chrome 37 | Edge 79 |
Firefox
53
Disabled
|
IE No | Opera Yes | Safari No | WebView Android No | Chrome Android No |
Firefox Android
53
Disabled
|
Opera Android No | Safari iOS No | Samsung Internet Android No |
完整支持
不支持
实验。期望将来行为有所改变。
见实现注意事项。
用户必须明确启用此特征。
<dialog>
.
HTMLDialogElement
open
returnValue
BeforeUnloadEvent
DOMStringMap
ErrorEvent
GlobalEventHandlers
HTMLAnchorElement
HTMLAreaElement
HTMLAudioElement
HTMLBRElement
HTMLBaseElement
HTMLBaseFontElement
HTMLBodyElement
HTMLButtonElement
HTMLCanvasElement
HTMLContentElement
HTMLDListElement
HTMLDataElement
HTMLDataListElement
HTMLDivElement
HTMLDocument
HTMLElement
HTMLEmbedElement
HTMLFieldSetElement
HTMLFormControlsCollection
HTMLFormElement
HTMLFrameSetElement
HTMLHRElement
HTMLHeadElement
HTMLHeadingElement
HTMLHtmlElement
HTMLIFrameElement
HTMLImageElement
HTMLInputElement
HTMLIsIndexElement
HTMLKeygenElement
HTMLLIElement
HTMLLabelElement
HTMLLegendElement
HTMLLinkElement
HTMLMapElement
HTMLMediaElement
HTMLMetaElement
HTMLMeterElement
HTMLModElement
HTMLOListElement
HTMLObjectElement
HTMLOptGroupElement
HTMLOptionElement
HTMLOptionsCollection
HTMLOutputElement
HTMLParagraphElement
HTMLParamElement
HTMLPictureElement
HTMLPreElement
HTMLProgressElement
HTMLQuoteElement
HTMLScriptElement
HTMLSelectElement
HTMLShadowElement
HTMLSourceElement
HTMLSpanElement
HTMLStyleElement
HTMLTableCaptionElement
HTMLTableCellElement
HTMLTableColElement
HTMLTableDataCellElement
HTMLTableElement
HTMLTableHeaderCellElement
HTMLTableRowElement
HTMLTableSectionElement
HTMLTemplateElement
HTMLTextAreaElement
HTMLTimeElement
HTMLTitleElement
HTMLTrackElement
HTMLUListElement
HTMLUnknownElement
HTMLVideoElement
HashChangeEvent
历史
ImageData
定位
MessageChannel
MessageEvent
MessagePort
Navigator
NavigatorGeolocation
NavigatorID
NavigatorLanguage
NavigatorOnLine
NavigatorPlugins
PageTransitionEvent
Plugin
PluginArray
PopStateEvent
PortCollection
PromiseRejectionEvent
RadioNodeList
Transferable
ValidityState
Window
WindowBase64
WindowEventHandlers
WindowTimers