Two timers in js (single timer Timeout and cycle timer Interval)

One-shot timer The
one-shot timer will run once when the time specified by parameter 2 arrives.

<script>
//设置单次定时器  在一秒之后执行getDate方法
t1 = setTimeout(getDate,1000);
//消除单次定时器
        clearTimeout(t1)
</script>

Recurring timer The
recurring timer will continue to run when the time specified by parameter 2 is reached

<script>
//设置循环定时器  每过一秒就执行getDate方法
t2 = setInterval(getDate,1000);
//消除循环定时器
        clearInterval(t2)
</script>

Guess you like

Origin blog.csdn.net/Hambur_/article/details/110235878