1 回答

TA貢獻(xiàn)1951條經(jīng)驗(yàn) 獲得超3個(gè)贊
您可以嘗試使用async/await這樣的方法:
// Return a promise that resolves after "miliseconds" milliseconds
function sleep(miliseconds) {
return new Promise(res => setTimeout(res, miliseconds));
}
// Make this function async function
async function printFailureMessages(failureMessages) {
for (var i = 0; i < failureMessages.length; i++) {
document.getElementById("myPopup").innerHTML = failureMessages[i];
document.getElementById("myPopup").classList.toggle("show");
await sleep(1500); // wait for this promise to finish
document.getElementById("myPopup").classList.toggle("show");
}
}
printFailureMessages(['Hello', 'World']);
- 1 回答
- 0 關(guān)注
- 97 瀏覽
添加回答
舉報(bào)