javascript密码匹配如果不匹配则在innerHTML中显示
您好,您编写的代码对我很有帮助,但当密码不匹配时,我想在innerHTML中显示消息。如何做到这一点,我正在尝试,但不为我工作。下面是我的代码。请指导我。我是初学者javascript密码匹配如果不匹配则在innerHTML中显示,javascript,Javascript,您好,您编写的代码对我很有帮助,但当密码不匹配时,我想在innerHTML中显示消息。如何做到这一点,我正在尝试,但不为我工作。下面是我的代码。请指导我。我是初学者 if (pwd != cpwd) { document.getElementById("pwd").innerHTML="password must be match"; document.getElementById("cpwd").innerHTML=
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;
}
我想知道如何准确地用innerHTML编写
在你的代码下面
<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!!!");
}
}
函数myFunction(){
var pass1=document.getElementById(“pass1”).value;
var pass2=document.getElementById(“pass2”).value;
if(pass1!=pass2){
//警报(“密码不匹配”);
document.getElementById(“pass1”).style.borderColor=“#E34234”;
document.getElementById(“pass2”).style.borderColor=“#E34234”;
}
否则{
警报(“密码匹配!!!”;
}
}
萨姆比特
谢谢你提前通知
等待您满意的回答。添加一个div,将您的密码验证响应存储到文档中,如
,然后在检查密码匹配后,您可以在该div的html中显示相应的结果
document.getElementById('validate').innerHTML=“密码不匹配!”代码>您应该使用绑定到字段“pass2”的事件onBlur
,以触发附加到问题的第一个代码段
例如:
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;
};
另一个选项是将其绑定到提交按钮。。什么是cpwd
和pwd
?你对哪一部分有问题?你到底想把它放在哪里..你的“pwd”和“cpwd”元素在哪里