不同类型的消息在网站依次弹出,某条消息中有操作时,操作完成后,继续弹后面的消息,怎么做?
2 回答
动漫人物
TA贡献1815条经验 获得超10个赞
这种流程控制都应该用promise
// 简易模态框const msg = text => { return new Promise(resolve=>{ const div = document.createElement("div");
div.setAttribute("style","position:fixed;left:50%;top:50%;width:200px;height:100px;transform:translate(-50%,-50%);z-index:9999;background:blue;");
div.innerText = text; const btn = document.createElement("button");
btn.setAttribute("style","position:absolute;right:0;top:-2em;");
btn.innerText = "关闭";
div.appendChild(btn);
btn.addEventListener("click",()=>{ document.body.removeChild(div);
resolve();
}); document.body.appendChild(div);
})
}// 使用(async ()=>{ await msg("How are you"); await msg("Fine"); await msg("Thanks"); await msg("And you");
})()添加回答
举报
0/150
提交
取消
