简体   繁体   English

jQuery不捕获表单提交

[英]JQuery not capturing form submit

I am using validationEngine to validate a form that is also launching a please wait modal. 我正在使用validationEngine来验证也在启动“请稍候”模式的表单。

Here's the code I am using to do this: 这是我用来执行此操作的代码:

$("#main_form").validationEngine({
        onValidationComplete: function(form, status){
            if(status) {
                ShowProgressAnimation();
                form.validationEngine('detach');
                form.submit();
            }
        }
    });

The issue I am having is I have a script that launches window.onbeforeunload. 我遇到的问题是我有一个启动window.onbeforeunload的脚本。

$("form").submit(function(e){
            window.onbeforeunload = UnPopIt;
        }); 

Normally it would ignore form submissions, but in this case because of the form.submit it's not. 通常,它将忽略表单提交,但是在这种情况下,由于form.submit并非如此。

Is there a proper way to detect this and stop the window.onbeforeunload from loading if it detects the form.submit? 如果检测到form.submit,是否有适当的方法来检测此问题并停止window.onbeforeunload的加载?

Thanks! 谢谢!

EDIT: I also forgot to add I think this issue only exists in IE. 编辑:我也忘记添加,我认为此问题仅在IE中存在。

The given script does not launch window.onbeforeunload , it just assigns a function to it. 给定的脚本不会启动window.onbeforeunload ,它只是为其分配一个功能。

If you want to prevent form submission, you need to return false in the submit handler: 如果要阻止表单提交,则需要在提交处理程序中返回false

$("form").submit(function(e){
    window.onbeforeunload = UnPopIt;
    return false;
}); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM