[英]Event input bug page when i long press a key on keyboard
the problem i have is in a input event, when i write my email, i have a function with input event who check if the e-mail is valid or no.我遇到的问题是在一个输入事件中,当我写我的 email 时,我有一个 function 带有输入事件,它检查电子邮件是否有效。 So when is not valid, i use a innerHTML for show a message invalid email.
因此,当无效时,我使用 innerHTML 来显示无效 email 的消息。 The problème is when i long press a key on my keyboard, my else is every time executed and my page slow down and bug?
问题是当我长按键盘上的一个键时,每次都执行我的 else 并且我的页面变慢并出现错误? How can i resolve this problem please: This is my JS code :
请问我该如何解决这个问题:这是我的JS代码:
let newsletter_email = document.getElementById('newsletter_email');
newsletter_email.addEventListener('input', function(e) {
let info_newsletter = document.getElementById('info_newsletter');
if(confirmEmail(newsletter_email.value)){
info_newsletter.innerHTML = "<h6 style='color: rgb(1, 196, 1);'>E-Mail valide !</h6>";
let interval_valid_email = setTimeout(function() {
info_newsletter.innerHTML = "";
}, 2000);
}else {
info_newsletter.innerHTML = "<h6 style='color:red;'>E-Mail non valide !</h6>";
e.preventDefault();
}
});
Thank u for help !谢谢你的帮助!
I advice you to use blur event我建议你使用模糊事件
Example:例子:
newsletter_email.addEventListener('blur', (e) => {
// Logic to check the email
});
So in this case, you check the email when the focus is lost.因此,在这种情况下,您在失去焦点时检查 email。 It's not usefull check the email when the user press a single character.
当用户按下单个字符时,检查 email 是没有用的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.