简体   繁体   English

避免提交表单两次 Parsley - Jquery

[英]Avoid submit form twice Parsley - Jquery

I'm trying to avoid submit form twice.我试图避免提交表单两次。 Basically, I would like to disable the submit button after the first click and if the form is validated.基本上,我想在第一次点击后禁用提交按钮,如果表单经过验证。

I'm using Parsley , and this is what I tried to do:我正在使用Parsley ,这就是我试图做的:

<script type="text/javascript">
    window.Parsley.on('parsley:form:validated', function(e){
        if (e.validationResult) {
            alert("OK");
            $('input[type=submit]').attr('disabled', 'disabled');
        }else{
            alert("KO");
        }
    });
</script>

But it seems like it never called.但它似乎从未调用过。 The alert never appears.警报永远不会出现。

What am I doing wrong?我究竟做错了什么?

Please, note that I added that script inside the layout that every page with a form extend.请注意,我在每个带有表单的页面扩展的布局中添加了该脚本。 So because of that I didn't use the id directly.因此,我没有直接使用 id。

I solved in this way:我是这样解决的:

<script type="text/javascript">
    $(function () {
        $('form').parsley().on('form:validated', function(e) {
            if (e.validationResult) {
                $('input[type=submit]').attr('disabled', 'disabled');
            }
        });
    });
</script>

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

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