Home > Article > Web Front-end > JavaScript method to implement counting based on setTimeout_javascript skills
The example in this article describes how JavaScript implements counting based on setTimeout. Share it with everyone for your reference. The specific implementation method is 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; }
I hope this article will be helpful to everyone’s JavaScript programming design.