JavaScript通过setTimeout计数的代码
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;
}
