pwdText.style.color = "red"; pwdText.style.fontSize = "13px"; } else { pwdText.innerHTML = ""; } }; //重复密码设置 pwdTwo.onblur = function() { var pwdV = document.querySelector("#pwd").value; var pwdTwoV = document.querySelector("#pwdTwo").value; if (pwdV ! = pwdTwoV) { pwdTwoText.innerHTML = "两次密码不一致"; pwdTwoText.style.color = "red"; pwdTwoText.style.fontSize = "13px"; } else { pwdTwoText.innerHTML = ""; } }; //密码框图标改变 var pwdImg = document.querySelector("#pwdImg"); pwdImg.onclick = function(){ if(pwd.type = "password"){ pwd.type="text"; pwdImg.src="img/显示.jpg"; }else{ pwd.type="password"; pwdImg.src="img/隐藏.jpg"; } }; phone.onblur=function(){ var phoneV = document.querySelector("#phone").value; var reg3 = /^1[3-9]{1}[0-9]{9}$/ if (phoneV.length == 0) { phoneText.innerHTML = "手机号码不能为空"; phoneText.style.color = "red"; phoneText.style.fontSize = "13px"; } else if (phoneV.length < 13) { phoneText.innerHTML = "手机号不能小于13"; phoneText.style.color = "red"; phoneText.style.fontSize = "13px"; } else if (phoneV.length > 13) { phoneText.innerHTML = "手机号不能大于13"; phoneText.style.color = "red"; phoneText.style.fontSize = "13px"; } else { phoneText.innerHTML = ""; } }; }; </script> </head> <body> <table> <tr> <td>账号:</td> <td> <input type="text" id="username" /> </td> <td id="usernameText"> </td> </tr> <tr> <td>密码:</td> <td id="pwdTd"> <input type="password" id="pwd" /> < img src="img/隐藏.jpg " id="pwdImg" /> </td> <td id="pwdText"> </td> </tr> <tr> <td>重复密码:</td> <td id="pwdTwoTd"> <input type="password" id="pwdTwo" /> < img src="img/隐藏.jpg " /> </td>
时间: 2023-05-19 22:06:58 浏览: 104
这段代码是用来设置密码输入框的样式和验证密码是否一致的。当密码输入框失去焦点时,会检查密码是否符合要求,如果不符合要求,则会将密码输入框的文字颜色设置为红色,字体大小设置为13px;如果符合要求,则清空密码输入框的内容。同时,还会检查重复密码是否与密码一致,如果不一致,则会提示用户重新输入。
阅读全文