執行 ❯
建立您
自己的
網站
×
更改方向
儲存程式碼
更改主題,深色/淺色
轉到 Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Promise Object</h1> <h2>The catch() Method</h2> <p id="demo"></p> <script> // Create a Promise Object let myPromise = new Promise(function(myResolve, myReject) { throw "Error 444"; }); // Using catch() myPromise.catch(x => myDisplay(x)); // Funtion to run when Promise is settled: function myDisplay(some) { document.getElementById("demo").innerHTML = some; } </script> </body> </html>