编程语言
首页 > 编程语言> > javascript – JQuery Validation插件submitHandler对我不起作用

javascript – JQuery Validation插件submitHandler对我不起作用

作者:互联网

您好我得到以下问题我的以下代码对我不起作用,我无法弄清楚为什么.我希望你们能帮助我.

编辑:提交处理程序根本不会被调用.我甚至没有得到警报信息.我想禁用提交按钮,直到表单被验证.

    $('form').validate({

        onsubmit: true,
        debug: true,
        errorLabelContainer: "#errorBox",
        rules: {
            user_email: {
                minlength: 4,
                email: true,
                required: true
            },
            user_textField: {
                minlength: 3,
                required: true
            },
            user_phone: {
                required: true,
                number: true,
                minlength: 4
            },
            user_fax: {
                number: true,
                minlength: 4
            },

            user_plz: {
                required: true,
                number: true,
                minlength: 5
            }
        },
        submitHandler: function (form) {
            $('form').find(":submit").attr("disabled", true).attr("value","Submitting...");
            alert("hie");
            form.submit();
        }
    }); 

我还有一个提交按钮:

<button class="btn btn-primary pull-right continuePaymentProcess" type="submit">Weiter</button>

最诚挚的问候格兰迪

解决方法:

您不需要onsubmit:true行,因为这是默认行为.重要:as per docs,

Validate the form on submit. Set to false to use only other events for validation. Set to a Function to decide for yourself when to run validation. A boolean true is not a valid value.

换句话说,您必须删除该行,因为true将破坏插件.

至于submitHandler“不工作”,它按照文档工作.当表单有效时,将触发submitHandler回调函数.

你说,“我想禁用提交按钮,直到表单被验证.”

由于在表单有效之前不会触发submitHandler,因此在验证表单之后才会触发禁用该按钮的代码.

请参阅您的代码:http://jsfiddle.net/aDAGL/

标签:javascript,jquery,html5,css3,jquery-validate
来源: https://codeday.me/bug/20190831/1776915.html