运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往空间
<!DOCTYPE html> <html> <body> <h1>JavaScript Promise Object</h1> <h2>The Promise.all() Method</h2> <p id="demo"></p> <script> // Create a Promise const myPromise1 = new Promise((resolve, reject) => { setTimeout(resolve, 200, "King"); }); // Create another Promise const myPromise2 = new Promise((resolve, reject) => { setTimeout(resolve, 100, "Queen"); }); // Both resolves. Who is faster? Promise.all([myPromise1, myPromise2]).then((x) => { myDisplay(x); }); // Funtion to run when a Promise is settled: function myDisplay(some) { document.getElementById("demo").innerHTML = some; } </script> </body> </html>