解釋 JavaScript 文字警示


JavaScript alert() 函式用於向用戶顯示一個彈出訊息。

以下是 JavaScript alert() 函式的程式碼 -

示例

 線上演示

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   }
</style>
</head>
<body>
<h1>Javascript text alert</h1>
<button class="Btn">CLICK HERE</button>
<h3>Click on the above button to trigger the alert popup</h3>
<script>
   let BtnEle = document.querySelector(".Btn");
   BtnEle.addEventListener("click", () => {
      alert("You pressed the button");
   });
</script>
</body>
</html>

輸出

以上程式碼將產生以下輸出 -

點選“點選這裡”按鈕 -

更新於: 2020 年 7 月 21 日

177 次瀏覽

開啟你的 職業生涯

完成本課程即可獲取認證

開始學習
廣告
© . All rights reserved.