[英]How to make a timer in js
So I left my old projects and decided to make a website like trello.com it's just a task list site and I wanted to make the task disappear after sometime but I don't know how to create a time I tried to make a string
nothing I tried everything I know help Here's the js所以我离开了我的旧项目并决定创建一个像 trello.com 这样的网站,它只是一个任务列表网站,我想让任务在一段时间后消失,但我不知道如何创建一个时间,我试图制作一个string
什么的我尝试了所有我知道的帮助 这是 js
//Don't care about the comment code
/*let todos = document.querySelector('ul')
let form = document.querySelector('form')
let idk = document.querySelector("[name='todo']")
let todo = []
*/
let timer = 80
/*function addtodos(todostext) {
todo.push(todostext)
const li = document.createElement('li')
const button = document.createElement('button')
li.innerHTML = todostext
button.innerHTML = "done"
todos.appendChild(li)
li.appendChild(button)
}
form.onsubmit =(event) =>{
event.preventDefault();
addtodos(idk.value)
}*/
function minustimer() {
--timer;
}
document.write(timer)
function clearInTimeout(timeSecond) {
setTimeout(() => {
// use you code clear
document.write("clear")
//
}, timeSecond * 1000)
}
clearInTimeout(5);
the "clear" will be print after 5 seconds “清除”将在 5 秒后打印
Inside an anonymous function of setInterval
, you can remove the task item (instead of my console.log).在setInterval
的匿名函数中,您可以删除任务项(而不是我的 console.log)。 The item will be removed after a specific amount of time given as a callback of setInterval
.该项目将在作为setInterval
回调给出的特定时间后被删除。 Basically, setInterval
waits some time to execute a code block.基本上, setInterval
会等待一些时间来执行代码块。 More information in https://developer.mozilla.org/en-US/docs/Web/API/setIntervalhttps://developer.mozilla.org/en-US/docs/Web/API/setInterval 中的更多信息
function minustimer(){
setInterval(()=>{
console.log("Remove the item after 5000 milliseconds")
},5000)
}
minustimer()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.