JavaScript implements counting method based on setTimeout
- 2020-06-12 08:24:59
- OfStack
This article illustrates the JavaScript counting method based on setTimeout. Share to everybody for everybody reference. Specific implementation methods are as follows:
var count = 0;
var timer;
var timerOn = false;
function timedCount() {
count++;
timer = setTimeout(function(){
timedCount()
}, 1000);
}
function doTimer() {
if (!timerOn) {
timerOn = true;
timedCount();
}
}
function stopCount() {
clearTimeout(timer);
timerOn = false;
}
Hopefully, this article has been helpful in your javascript programming.