<html>
<head>
<script type="text/javascript">
let c=0
let t
timedCount=()=>
{
document.getElementById('txt').value=c
c=c+1
t=setTimeout(timedCount(),1000)
}
stopCount=()=>
{
clearTimeout(t)
}
</script>
</head>
<body>
<form>
<input type="button" value="开始计时!" onClick="timedCount()">
<input type="text" id="txt">
<input type="button" value="停止计时!" onClick="stopCount()">
</form>
</body>
</html>
let timer=null
timeOut = () => {
timer = setTimeout(() => {
console.log('执行')
this.timeOut()
}, 5 * 60 * 1000)
}
// 卸载定时器
clearTimeout(timer)