gpt4 book ai didi

javascript - 如何让我的程序连续运行

转载 作者:行者123 更新时间:2023-11-30 12:05:47 25 4
gpt4 key购买 nike

我想让我的程序连续运行,以便在完成后 2 秒后再次运行。

这是我的代码:

$(document).ready(function () {

var colorBlocks = [
'skip',
'yellow',
'green',
'blue',
'white',
'orange'
]

function colourBoard() {
$.each(colorBlocks, function (i) {
setTimeout(function() {
$('#' + this).css("background", this);
setTimeout(function() {
$('#' + this).css("background", '#212121');
}.bind(this), i * 200);
}.bind(this), i * 500);
});
}
colourBoard();
});

最佳答案

我建议使用 setInterval()为此:

var myVar = setInterval(myTimer, 1000);

function myTimer() {
var d = new Date();
document.getElementById("demo").innerHTML = d.toLocaleTimeString();
}

关于javascript - 如何让我的程序连续运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35280948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com