var p=document.getElementById("demo");async function myFunction(){await new Promise(function(resolve){setTimeout(function(){
p.innerHTML="延时成功";resolve();},1000);});}myFunction();
第二种
var p=document.getElementById("demo");async function myFunction(){
//当不用进行什么操作,只需延时时以下一行代码可以搞定
await new Promise(resolve => setTimeout(resolve, 1000));await new Promise(resolve=>setTimeout(()=>{
p.innerHTML="延时成功";resolve();},1000));}myFunction();
第三种
var p=document.getElementById("demo");function delay(time){return new Promise(function(resolve){setTimeout(function(){
p.innerHTML="延时成功";resolve();},time);});}async function myFunction(){
await delay(1000);}myFunction();