[英]Password confirmation Javascript
我有一个简单的注册表,我决定添加确认密码的功能,即使我输入其他密码也似乎无法检查!
我的代码中有错误吗?
$(document).ready(function(){
$('input[name=c_password]').keyup(password_check);
});
function password_check(){
var password = $('input[name=password]').val();
var c_password = $('input[name=c_password]').val();
if(c_password != password || c_password.length < 6){
//alert("test");
$('input[name=c_password]').parent().addClass( "has-error has-feedback" );
}else{
$('input[name=c_password]').parent().removeClass( "has-success has-feedback" );
}
}
谢谢!
您的代码几乎是正确的,除了在正确的c_password情况下忘记删除类has-error之外。
$('input[name=c_password]').parent().removeClass("has-error")
if(c_password != password || c_password.length < 6){
//alert("test");
$('input[name$=password]').parent().addClass( "has-error has-feedback" );
}else{
...
(you need put a 'url' on ajax)
看来您刚刚省略了一些代码。 根据您提供的信息,我猜您需要这样的东西:
if(c_password != password || c_password.length < 6){
// This is the additional code
$('input[name=c_password]').parent().addClass( "has-error has-feedback" );
}else{
jQuery.ajax({
success: function(response){
...
}
}
这些内容应该会向用户突出显示错误。 不要忘记验证服务器端,客户端只是为了用户方便。
编辑:实际上,让我们忽略最后的编辑:/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.