解决方法
可以使用对话框边界检测背景点击.
var dialog = document.getElementByTagName('dialog'); dialog.showModal(); dialog.addEventListener('click',function (event) { var rect = dialog.getBoundingClientRect(); var isInDialog=(rect.top <= event.clientY && event.clientY <= rect.top + rect.height && rect.left <= event.clientX && event.clientX <= rect.left + rect.width); if (!isInDialog) { dialog.close(); } });