gpt4 book ai didi

jquery - jQuery 验证插件的密码确认问题

转载 作者:行者123 更新时间:2023-12-01 03:48:33 25 4
gpt4 key购买 nike

我不明白为什么我的代码不起作用,密码确认不询问 - “密码需要确认”。

我的js代码:

    $(document).ready(function(){
$('.new_user').validate({
debug: true,
rules: {
'user[email]':{
required: true
},
'user[password]': {
required: true,
'user[password_confirmation]': {
equalTo: "#user_password"
}
}

},

showErrors: function(errorMap, errorList) {
this.defaultShowErrors();
},
success: "valid"

});
})

我的html代码:

   <div><label for="user_password">Password</label><br>
<input id="user_password" name="user[password]" size="30" type="password" class="error"><label for="user_password" generated="true" class="error" style="">This field is required.</label></div>

<div><label for="user_password_confirmation">Password confirmation</label>
<input id="user_password_confirmation" name="user[password_confirmation]" size="30" type="password"></div>

最佳答案

工作演示 http://jsfiddle.net/g45fM/1/

演示中的这个版本比您正在尝试的版本要干净得多,而且您的 HTML 中缺少 form

希望这有帮助。

代码

$.validator.setDefaults({
submitHandler: function() {
alert("submitted!");
}
});

// validate signup form on keyup and submit
$("form").validate({
rules: {
pass: {
required: true,
minlength: 5
},
pass2: {
required: true,
minlength: 5,
equalTo: "#pass"
}
},
messages: {
pass: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
pass2: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long",
equalTo: "Please enter the same password as above"
}
}
});​

关于jquery - jQuery 验证插件的密码确认问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11070105/

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