我有以下脚本
function validateEmailp() {
var messagemail = document.getElementById('emailerrorz').innerText;
var two = document.getElementById('email').value;
var first = two.split("@")[1];
var badEmails = ["gmail.com", "yahoo.com"]
if (badEmails.indexOf(first) != -1) {
document.getElementById("email").value = ""; //this works
messagemail = 'We do not accept free e-mails'; //this doesn't
return false;
}
return true;
}
和 HTML
<td>{EMAILFIELD}<span id="emailerrorz"></span></td>
和 {EMAILFIELD} 在 PHP
<input id="email" class="txt" type="text" name="email" size="25" value="" maxlength="255" onblur="validateEmailp()"></input>
但它对我在跨度 ID 中打印错误不起作用。它仅适用于从那里重置值。