<div id="show"></div> <script type="text/javascript"> let show = document.getElementById('show'); function addShow(e){ show.innerHTML += e; return console.log(show.innerHTML); } async function pause(){ for(let i = 0; i < 10;i++){ let showData = new Promise((resolve,reject)=>{ setTimeout(()=>{ let makeSure = confirm('确认继续?'); //在调用 confirm() 时,将暂停对 JavaScript 代码的执行,在用户作出响应之前,不会执行下一条语句。直到这个对话框被点击后, 后面的脚本才会运行. if(makeSure === true){ addShow(i); resolve(); }else{ console.log('loop is stop'); reject(); } },2000) }); await showData; // console.log(i); } } pause(); </script>