onbeforeunload 有问题。我有一个通过 jquery 向导插件分成几段的长表单。如果您在任何步骤中回击、刷新、关闭等,我需要弹出一个确认对话框,但需要它在单击提交按钮时不弹出确认对话框。有它的工作,或者至少我认为,它现在没有。
<script type="text/javascript">
var okToSubmit = false;
window.onbeforeunload = function() {
document.getElementById('Register').onclick = function() { okToSubmit = true; };
if(!okToSubmit) return "Using the browsers back button will cause you to lose all form data. Please use the Next and Back buttons on the form";
};
</script>
'Register' 是提交按钮 ID。请帮忙!