HLJ 发布于
2022-09-05 08:47:20

JS中使用async await和setTimeout同时使用输出的结果实例

<html>
<head>
</head>
<body>
<h1> Example of using sleep() in JavaScript </h1>
<script>
   function sleep(milliseconds) {
      return new Promise(resolve => setTimeout(resolve, milliseconds));
   }
   async function fun() {
      document.write('Hello World');
      for (let i = 1; i <=10 ; i++) {        
         await sleep(2000);
         document.write( i + " " + "Welcome to the javaTpoint.com" + " " + "</br>");
      }
   }
   fun();
</script>
</body>
</html>

https://www.javatpoint.com/javascript-sleep

当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2022-09-05/595.html
最后生成于 2023-06-27 21:38:26
此内容有帮助 ?
0