setTimeout无法消失<p>标签

时间:2019-01-26 12:31:24

标签: javascript

我是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();

}

1 个答案:

答案 0 :(得分:1)

问题是

if (revealText === true)

revealText是一个返回布尔值的函数,您需要将其更改为

if (revealText() === true)
相关问题