gpt4 book ai didi

javascript - 如何在 javascript 中检测某个字段是否处于焦点并清除除此之外的错误?

转载 作者:行者123 更新时间:2023-12-02 18:17:07 25 4
gpt4 key购买 nike

我有这个功能

function validateEmailp() {
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 = "";
document.getElementById('emailerrorz').innerText = 'We do not accept free e-mails'
return false;
}
return true;
}

HTML 是

<input id="email" onblur="validateEmailp()"><div id="emailerrorz"></div>

用户在输入字段中输入免费电子邮件后,他将收到该错误(我们不会..)但在他将电子邮件更正为非免费电子邮件后,错误应该会消失。我如何使用 JavaScript 做到这一点?

最佳答案

function validateEmailp() {
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 = "";
document.getElementById('emailerrorz').innerText = 'We do not accept free e-mails'
return false;
}
document.getElementById('emailerrorz').innerText = ''
return true;
}

关于javascript - 如何在 javascript 中检测某个字段是否处于焦点并清除除此之外的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19178322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com