簡體   English   中英

使用 JavaScript 的密碼確認未更新

[英]Password confirmation using JavaScript doesn't get updated

我有一個注冊表。 它成功檢查了密碼輸入和確認密碼輸入的值。 (如果兩個密碼匹配,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>

更新我將“匹配”更改為 ==,一切似乎都運行良好。

if (document.getElementById("confirm_password").value == document.getElementById("password_new").value){...

您如何嘗試在其中添加其他條件,例如

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");
}
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM