我需要该功能在第一次 8 秒后重复,然后在 30 秒后再次重复。我使用过 setTimeout 但不确定这是否是解决方法。谢谢你。
问问题
464 次
3 回答
6
您可以使用setTimeout
and的连词setInterval
:
window.setTimeout(function() {
// this will run 8 seconds later
window.setInterval(function() {
// do here whatever you want to do at 30 seconds intervals
}, 30000);
}, 8000);
于 2012-06-13T16:56:14.013 回答
2
setTimeout 是完美的。
(function() {
var func = function() {
// Code here
}
setTimeout(func, 8000);
setTimeout(func, 30000);
})();
于 2012-06-13T16:56:38.740 回答
0
使用 JavaScript:
var interval = setInterval(yourFunction, 8000);
其中 8000 是再次执行函数的间隔,interval 是间隔句柄,以防您想使用 clearInterval 停止它
于 2012-06-13T16:57:28.460 回答