jQuery验证插件禁用按钮

时间:2016-12-29 21:24:53

标签: javascript jquery jquery-validate

我正在尝试在我的表单上禁用我的提交按钮,但似乎我正在做的事情不起作用。 jQuery验证插件正在我的表单上工作并且它正确验证,但是当提交表单时...提交按钮在我调用它时不会禁用。还值得注意的是ajax功能正在运行,数据正在传输到我的数据库表。

这是我的代码

HTML

<form class='sign_up' action='' method='POST'>                
            <input id='email' type="text" name="email" placeholder="Email">
            <input id='username' type="text" name="username" placeholder="Username">
            <input type="password" name="password" placeholder="Password">
            <input id='registerBtn' name='registerBtn' type="submit" value="Create Account">
        </form>

的jQuery

$(".sign_up").validate({
        errorElement: 'div',
        rules: {
            email: {
                required: true,
                maxlength: 60,
                email: true,
                remote: {
                    url: 'usernameChecker.php',
                    type: 'post',
                    data: {
                        email: function(){
                            return $("#email").val();
                        },
                    },
                },
            },

            username: {
                required: true,
                maxlength: 15,
                alphanumeric: true,
                remote: {
                    url: 'usernameChecker.php',
                    type: 'post',
                    data: {
                        username: function(){
                            return $("#username").val();
                        },
                    },
                },
            },

            password: {
                required: true,
                minlength: 7,
            }

        },

        messages: {
            email: {
                required: "*Please enter your email.",
                maxlength: "*Emails should not exceed 60 characters.",
                email: "*This is not a valid email.",
                remote: "*That email is already taken."
            },

            username: {
                required: "*Please enter a username.",
                maxlength: "*Username should not exceed 15 characters.",
                alphanumeric: "*Usernames should contain only letters, numbers or underscores.",
                remote: "*That username is already taken."
            },

            password: {
                required: "*Please enter a password.",
                minlength: "*Your password should be at least 7 characters long.",
            }
        },

          submitHandler: function(form) {
          $("#registerBtn").prop("disabled", "disabled");
            $(form).ajaxSubmit();
          }
    });

0 个答案:

没有答案