简体   繁体   English

javascript密码匹配(如果不匹配)在innerHTML中显示

[英]javascript password match if not match show in innerHTML

hi you write that code that is helpful for me but i want to show message in innerHTML when password not match how to do this i am trying but not working for me.below is my code .please guide me. 您好,您编写了对我有帮助的代码,但是当密码不匹配时,我想在innerHTML中显示消息,我正在尝试但不为我工作。以下是我的代码。请指导我。 i am beginner learner. 我是初学者。

                if (pwd != cpwd) {

                 document.getElementById("pwd").innerHTML="password must be match";
     document.getElementById("cpwd").innerHTML="password must be match";
     document.getElementById("pwd").style.color="RED";

      return false;

} }

i want to know about how to exactly write in innerHTML 我想知道如何完全用innerHTML编写

below your code 在您的代码下方

               <input id="pass1" type="password" placeholder="Password" style="border-radius:7px; border:2px solid #dadada;" /> <br />
               <input id="pass2" type="password" placeholder="Confirm Password" style="border-radius:7px; border:2px solid #dadada;"/> <br />

 <script>
function myFunction() {
    var pass1 = document.getElementById("pass1").value;
    var pass2 = document.getElementById("pass2").value;
    if (pass1 != pass2) {
        //alert("Passwords Do not match");
        document.getElementById("pass1").style.borderColor = "#E34234";
        document.getElementById("pass2").style.borderColor = "#E34234";
    }
    else {
        alert("Passwords Match!!!");
    }
}

Sumbit 求和

Thanks for advance waiting for your appreciate answer. 感谢您提前等待您的答复。

You should use the event onBlur tied to the field "pass2" in order trigger the first code snippet attached to your question. 您应该使用绑定到字段“ pass2”的onBlur事件,以触发附加到您的问题的第一个代码段。

For example: 例如:

document.getElementById("pass2").onblur=function(){
    var pass1 = document.getElementById("pass1").value;
    var pass2 = document.getElementById("pass2").value;
    if (pass1 != pass2) {
      document.getElementById("pass1").innerHTML="password must be match";
      document.getElementById("pass2").innerHTML="password must be match";
      document.getElementById("pass1").style.color="RED";
      return false;
     }
     return true;    
};

Another option is to tie it to the submit button. 另一个选择是将其绑定到提交按钮。

添加一个div来存储对<div id='validate'></div>类的文档的密码验证响应,然后在检查密码是否匹配后,可以在此div document.getElementById('validate').innerHTML="passwords do not match!";的html中显示适当的结果.getElementById document.getElementById('validate').innerHTML="passwords do not match!";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM