开发者_开发知识库Exact Duplicate:
how can I execute javascript code every a specific time interval ?
Is there an efficient method for causing a javascript (ChangeDivBG()
, in my case) function to execute every fixed time interval?
setInterval(ChangeDivBG, 1000); // 1000 is time interval in miliseconds - 1000ms=1sec
You can use setInterval
function
setInterval(ChangeDivBG, delay);
If you want to pass an argument:
setInterval(function(color){ ChangeDivBG(color) }, delay);
If you pass an argument like this:
setInterval(ChangeDivBG, delay, color);
It won't work in IE(under IE9), be careful about that.
use setInterval (func, t).
setInterval(ChangeDivBG, 1000)
t is in milliseconds.
精彩评论