所以我的代码基本上是告诉用户他们的注册出了什么问题,一切正常,但只有一件事。Div 应该更新文本字段以说明他们的注册有什么问题,但事实并非如此,这是我的 JavaScript
window.onload = initPage;
submitBtn = document.getElementById("submit");
errorText = document.getElementById("errortext");
function initPage() {
document.getElementById("password2").onkeyup = checkPassword;
document.getElementById("password2").onblur = checkPassword;
document.getElementById("email2").onkeyup = checkEmail;
document.getElementById("email2").onblur = checkEmail;
submitBtn.disabled = false;
}
function checkPassword() {
var password1 = document.getElementById("password1").value;
var password2 = document.getElementById("password2").value;
if (password1 != password2) {
document.getElementById("password1").className = "denied";
document.getElementById("password2").className = "denied";
submitBtn.disabled = true;
document.getElementById("submit").className = "denied";
errorText.innerHTML = "Passwords do not match.";
} else {
document.getElementById("password1").className = "password2";
document.getElementById("password2").className = "password2";
document.getElementById("submit").className = "button1";
submitBtn.disabled = false;
errorText.innerHTML = "";
}
}
function checkEmail() {
var email1 = document.getElementById("email1").value;
var email2 = document.getElementById("email2").value;
if (email1 != email2) {
document.getElementById("email1").className = "denied";
document.getElementById("email2").className = "denied";
submitBtn.disabled = true;
document.getElementById("submit").className = "denied";
errorText.innerHTML = "Emails Do Not Match.";
} else {
document.getElementById("email1").className = "regtext";
document.getElementById("email2").className = "regtext";
submitBtn.getElementById("submit").disabled = true;
document.getElementById("submit").className = "button1";
errorText.innerHTML = "";
}
}
这是我的 div
<tr><td colspan="2"><div id="errortext"></div></td></tr>