js实现无需确定弹窗和for循环等待

function tempAlert(msg,duration) { var el = document.createElement("div"); el.setAttribute("style","position:absolute; top:8%; right:8%; background-color:#FF6347; color:#FFE4B5; height:100px; width:300px; font-size:200%; text-align:center; line-height:100px; box-shadow:0px 0px 10px #FF7F50; border-radius: 15px 50px"); el.innerHTML = msg; setTimeout(function(){ el.parentNode.removeChild(el); },duration); document.body.appendChild(el); }async function test() { for(let i=0; i<5; i++){ console.log(i) tempAlert('The '+i+' page begins',4000) await sleep(5000) } }function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)) }test()

    推荐阅读