我想以几种形式检查密码输入。我没有收到任何错误消息,但我不知道为什么它不起作用。任何ideads如何解决它?感谢
Link:
link
答案 0 :(得分:0)
js代码中几乎没有更正:请参阅下面的代码:
this.passwordInputs.length
至this.value.length
var pgMsg = document.querySelector(".form-container p");
至var pgMsg = document.querySelector(".form-element p");
var error = "";
var passwordInputs = document.querySelectorAll('input[type=password]');
if (passwordInputs.length > 1) {
for (var i = 0; i < passwordInputs.length; i++) {
var passwordInputsList = passwordInputs[i];
passwordInputsList.addEventListener("blur", passwordCheck, false);
}
}
function passwordCheck() {
if (this.value.length < 8) {
error = "Password is too short";
var pgMsg = document.querySelector(".form-element p");
pgMsg.textContent = error;
console.log(pgMsg.textContent);
}
}
<div class="form-element">
<label for="register-password"></label>
<img src="img/Icons/password.png" alt="Password Icon">
<input type="password" name="password" id="register-password" placeholder="Password">
<p class="pg-valid" id="pg-valid"></p>
</div>
<div class="form-element">
<label for="register-password-repeat"></label>
<img src="img/Icons/password.png" alt="Password Icon">
<input type="password" name="password-repeat" id="register-password-repeat" placeholder="Confirm Password">
</div>
<div class="form-element">
<label for="signin-password"></label>
<img src="img/Icons/password.png" alt="Password Icon">
<input type="password" id="signin-password" name="password" placeholder="Password">
</div>