【发布时间】:2023-02-16 19:00:50
【问题描述】:
除了单击 Esc 按钮之外,您如何通过单击外部来关闭 dialog 框?
<!DOCTYPE html>
<html>
<body>
<p>Click the button to show the dialog.</p>
<button onclick="myFunction()">Show dialog</button>
<p><b>Note:</b> Use the "Esc" button to close the modal.</p>
<p><b>Note:</b> The dialog element is only supported in Chrome 37+, Safari 6+ and Opera 24+.</p>
<dialog id="myDialog">This is a dialog window</dialog>
<script>
function myFunction() {
document.getElementById("myDialog").showModal();
}
</script>
</body>
</html>
【问题讨论】:
-
click事件处理程序和body或全视图覆盖上的keypress事件处理程序。 -
您的问题与 Blazor 无关。
标签: javascript html