JavaScript , , . (, for, , , .)
setTimeout() setInterval() ( window). , ; , . , "", .
, :
function launch() {
var inc = 0,
max = 9999;
delay = 100;
function timeoutLoop() {
document.getElementById('result').innerHTML = inc;
if (++inc < max)
setTimeout(timeoutLoop, delay);
}
setTimeout(timeoutLoop, delay);
}
, timeoutLoop() setTimeout() - .
setTimeout() setInterval() , , clearTimeout() clearInterval(), - , , :
function launch() {
var inc = 0,
max = 9999;
delay = 100;
var iID = setInterval(function() {
document.getElementById('result').innerHTML = inc;
if (++inc >= max)
clearInterval(iID);
},
delay);
}
, delay . , inc , , , launch(): .