方法在jquery中不起作用

方法在jquery中不起作用

$('#reg_form').validate({
                onkeyup: false,
                errorClass: 'error',
                validClass: 'valid',
                rules: {
                    username: {
                        required: true,
                        minlength: 5,
                        //remote: "user_check.php"
                    },
                    password: {
                        required: true,
                        minlength: 5
                    },
                    confirm_password: {
                        required: true,
                        minlength: 5,
                        equalTo: "#password"
                    },
                    secretQuestion: "required",
                    secretAnswer: "required",
                    emailId: {
                        required: true,
                        email: true
                    },
                    termsConditions: "required"
                },
                messages:{
                    username: {
                        required: "Please enter Username",
                        minlength: "Please enter atleast 5 characters",
                        //remote: jQuery.format("{0} is already in use")
                    },
                    password: {
                        required: "Please provide a password",
                        minlength: "Your password must be at least 5 characters long"
                    },
                    confirm_password: {
                        required: "Please provide a password",
                        minlength: "Your password must be at least 5 characters long",
                        equalTo: "Please enter the same password as above"
                    },
                    secretQuestion: "Please select your question",
                    secretAnswer: "Please enter your secret answer",
                    emailId: "Please enter a valid email address",
                    termsConditions: "Please accept our Terms and COnditions"
                },
                highlight: function(element) {
                    $(element).closest('div').addClass("f_error");
                },
                unhighlight: function(element) {
                    $(element).closest('div').removeClass("f_error");
                },
                errorPlacement: function(error, element) {
                    $(element).closest('div').append(error);
                }
            });

最佳答案

通过“规则:”设置验证时,需要输入的“名称”而不是“ id”。

所以对于这样的输入:

<input type="text" name="password_name" id="password_id></input>
<input type="text" name="confirm_password_name" id="confirm_password_id></input>


您应该在验证中更改此设置:

password_name: {
  required: true,
  minlength: 5
},
confirm_password_name: {
  required: true,
  minlength: 5,
  equalTo: "#password_id"
}


希望它能工作。

关于jquery - equalTo()方法在jquery中不起作用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11361378/

10-09 22:19