var board = new DepartureBoard(document.getElementById('test'), {
rowCount: 1,
letterCount: 13
});
window.setTimeout(function() {
board.setValue(['VISA SERVICES', ]);
}, 0)
window.setTimeout(function() {
board.setValue(['POE CLEARENCE', ]);
}, 8000);
window.setTimeout(function() {
board.setValue(['STAMPING', ]);
}, 16000);
window.setTimeout(function() {
board.setValue(['ATTESTATION', ]);
}, 24000);
window.setTimeout(function() {
board.setValue(['INSURANCE', ]);
}, 32000);
window.setTimeout(function() {
board.setValue(['FOREX', ]);
}, 40000);
https://codepen.io/Mtn_Wolf/pen/LKsvz
我正在尝试像机场起飞一样,但我无法在我的网站上显示的最后一个值之后循环该值以向服务显示我如何在最后一个显示的内容之后循环该值
最佳答案
在现代 ECMAScript 中使用直接超时不是好的模式,不仅仅是因为“现代方法”,还因为更好的链接和错误处理
function delay(time) { return new Promise(resolve => setTimeout(resolve, time) }
function worker() {
return Promise.resolve()
.then(() => board.setValue(['VISA SERVICES']))
.then(() => delay(1000))
// and so on
.then(worker);
}
worker().catch((error) => {
// Error handling here
})
关于javascript - 如何在最后一个值之后循环这个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45343102/