setTimeout() will only launch the command once. In this case, setInterval() is your friend.
var iFrequency = 5000; // expressed in miliseconds
var myInterval = 0;
// STARTS and Resets the loop if any
function startLoop() {
if(myInterval > 0) clearInterval(myInterval); // stop
myInterval = setInterval( "doSomething()", iFrequency ); // run
}
function doSomething()
{
// (do something here)
}
from code...
<input type="button" onclick="iFrequency+=1000; startLoop(); return false;"
value="Add 1 second more to the interval" />
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…