gpt4 book ai didi

jquery - equalTo() 方法在 jquery 中不起作用?

转载 作者:行者123 更新时间:2023-12-01 02:22:44 24 4
gpt4 key购买 nike

$('#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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com