[英]setTimeout not working to dissapear <p> tag
我是JS的新秀,并且正在从事一个需要我制作无法正常运行的验证系统的项目。 这是我目前的代码:
我不知道为什么setTimeout无法正常工作,我也检查了其他帖子,但不了解。 似乎我的函数dissapearText没有被识别,因为我有一个console.log作为测试它是否运行的测试,但是它没有出现在devtools控制台中。 任何简单的解决方案都可以。
谢谢,亚瑟
{
let validation = document.querySelector('.type__style');
let validation2 = document.getElementById("label__text");
const init = () =>{
const $button = document.getElementById('send__button');
$button.onclick = () => {
revealText();
setTimeout(dissapearText,4000);
}
const revealText = () => {
if (validation.value === ""){
validation.focus();
window.alert("Please enter your name.");
return false;
}else if(validation2.value === ""){
validation2.focus();
window.alert("Please fill in commentary.");
return false;
}else{
document.querySelector('.feedback').style.opacity = 1;
return true;
}
}
const dissapearText = () => {
if (revealText === true){
console.log("sup");
document.querySelector('.feedback').style.opacity = 0;
}
}
}
init();
}
问题是
if (revealText === true)
revealText
是一个返回布尔值的函数,您需要将其更改为
if (revealText() === true)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.