jQuery密码匹配验证 - 错误消息不隐藏

时间:2015-04-29 16:19:34

标签: jquery forms validation

使用基本注册表格。用户应输入密码,然后再输入密码,当他们在“确认密码”框中输入密码时,如果密码必须匹配,则应说“密码必须匹配”,如果匹配则不显示任何错误。它会在没有显示错误的情况下加载,并且在输入确认框时会显示错误,但是在输入匹配的密码后错误不会消失。我需要修理什么?

jQuery脚本:

$(":password").change(function(){                               
    if($("#passConfirm").val() != $("#password").val() ){
        $("#matchText").show()
    }
    else{
        $("#matchText)").hide();
        }
}); 

表格的相关部分:

Password: 
<input type="password" id="password" placeholder="Password" >
</br>
</br>

Confirm Password: 
<input type="password" id="passConfirm" placeholder="Password" >
<span class="error" id="matchText" style="display:none;">Passwords must match.</span>

1 个答案:

答案 0 :(得分:2)

您的代码中有拼写错误:

$("#matchText)").hide();

应该是

$("#matchText").hide();

由于ID为#matchText但不是#matchText)

相关问题