简体   繁体   中英

ClearInterval: The function body was executed after the expected time but i can't seem to get it off the screen afterwards

The clearInterval() method is not working after execution of the function body. here's the code snippet:

const clearAll = () =>{
   const del = setTimeout(() => Display.textContent = 'deleted',100);
  clearTimeout(del)
}
clearBtn.addEventListener("click", clearAll)

It seems you delete the timeout before it happens at least once. Try calling clearTimeout after it executes.

const clearAll = () => {
   const del = setTimeout(() => {
      Display.textContent = 'deleted';
      clearTimeout(del);
   }, 100);
};
clearBtn.addEventListener("click", clearAll);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM