使用Jquery比较两个密码 [英] Comparing two passwords with Jquery

查看:133
本文介绍了使用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())

这篇关于使用Jquery比较两个密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆