使用JavaScript的密码确认未更新

问题描述 投票:0回答:1

我有一张注册表。它成功检查了密码输入和confirm_password输入的值。 (如果两个密码匹配,则X更改为✔️)问题是,出现复选标记后,它似乎卡在那里了!当我更改密码时,复选标记应更改为X,但不会更改!卡在✔️!

<div    id="confirm_pass2">
  <span id="password_confirmation"  class="unconfirmed_pass"></span>
</div>

  <script>
        var confirmation = document.getElementById("confirm_password");
                confirmation.onfocus = function (){
                document.getElementById("confirm_pass2").style.display = "block";
            }
            confirmation.onblur = function (){
                document.getElementById("confirm_pass2").style.display = "none";
            }
            confirmation.onkeyup = function () {
        if (document.getElementById("confirm_password").value.match(document.getElementById("password").value)){
            document.getElementById("password_confirmation").classList.remove("unconfirmed_pass");
            document.getElementById("password_confirmation").classList.add("confirmed_pass");
        }   }
        </script>



<style>
 #confirm_pass2 {
    position: absolute;
    display: none;
}
.confirmed_pass:before {
    position: absolute;
    font-size: 25px;
    right: 642px;
    bottom: 197px;
    font-weight: bold;
    color: green;
    content: "✔";
}
.unconfirmed_pass:before {
    font-family: calibri;
    position: absolute;
    right: 647px;
    bottom: 205px;
    font-size: 22px;
    font-weight: bold;
    color: red;
    content: "X";
}
</style>

UPDATE我将“匹配”更改为==,一切似乎都正常进行。

if (document.getElementById("confirm_password").value == document.getElementById("password_new").value){...
javascript validation confirmation password-confirmation password-checker
1个回答
0
投票

您如何尝试在其中添加其他条件呢?

confirmation.onkeyup = function () { 
if (document.getElementById("confirm_password").value.match(document.getElementById("password_new").value)){ 
document.getElementById("password_confirmation").classList.remove("unconfirmed_pass"); document.getElementById("password_confirmation").classList.add("confirmed_pass"); 
} else {
document.getElementById("password_confirmation").classList.remove("confirmed_pass"); document.getElementById("password_confirmation").classList.add("unconfirmed_pass");
}
 }
© www.soinside.com 2019 - 2024. All rights reserved.