1 回答

TA贡献1951条经验 获得超3个赞
您可以尝试使用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 关注
- 70 浏览
添加回答
举报