所以我的代碼基本上是告訴用戶他們的註冊有什麼問題,一切正常,但一件事。股利應更新文本字段說有什麼錯他們的註冊,但它不是,這是我的JavaScript爲什麼我的div沒有正確更新?
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>
你間接地幫我解決這個問題,謝謝。 。還有一個問題,電子郵件是頁面上的最後兩個文本字段,所以你不能onblur,並且onkeyup不能正確更新它,該按鈕被禁用,並且當我完成打字時文本仍然出現,怎麼可能我可以在不模糊的情況下正確更新 – Gacnt
不客氣!但我不知道你對其他問題的含義。你能解釋一下嗎? –
好了,我的表單上的最後2個文本字段是電子郵件和確認電子郵件,只要我輸入確認電子郵件,它應該檢查,確認它沒問題,並啓用提交按鈕,以及清除在上面我的代碼中可以看到的文本,但由於某種原因它不會在keypressup上更新 – Gacnt