使用Jquery比较两个密码
问题描述:
我正在尝试比较用户在尝试注册时将输入的两个密码,但是每当密码等于确认密码的密码仍然会抛出错误密码不匹配时. 如果没有输入密码,则有两个阶段,然后会出现一个可以正常工作的错误,但是第二阶段比较两个密码时,该错误始终为真并自行显示.
I'm trying to compare two passwords that a user will enter when trying to register but whenever a password is equal to that of the confirmed password is still throws the error passwords don't match. There's two stages to this if no password is entered then a error is presented that works fine, but the second stage comparing two password the errors is always true and presents it self.
if ($('#password').val() == "") {
$('.error').append("<li> Please enter a pasword </li>");
error = true;
} else if ($('#password') !== $('#password1')) {
$('.error').append("<li> You password does not match the confirmed password </li>");
error = true;
}
答
比较它们之间的密码时,还必须使用.val()
:
You also have to use .val()
when comparing the passwords between themselves:
else if ($('#password').val() !== $('#password1').val())