【发布时间】:2020-01-23 20:58:21
【问题描述】:
如何在不使用任何第三方库(例如 jQuery)的情况下,在提交表单时禁用 onbeforeunload 事件?
我有:
HTML:
<form id="confirm_form">
<input id="confirm_btn" type="submit" value="Confirm Action">
</form>
JS:
function onLeave() {
return "Are you sure you wish to leave without performing the action?";
}
window.onbeforeunload = onLeave;
这个问题不是 How to disable beforeunload action when user is submitting a form? 或 window.onbeforeunload - Only show warning when not submitting form 的重复问题,因为它们专门处理 jQuery。
【问题讨论】: