HTML Window alert() 方法


HTML window alert() 方法以 HTML 文件中定義的訊息和一個確定按鈕的形式顯示一個警報框。

語法

以下是語法 −

alert(“message”);

讓我們看一個 HTML window alert() 方法的示例 −

示例

 線上演示

<!DOCTYPE html>
<html>
<head>
<style>
   body {
      color: #000;
      height: 100vh;
      background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
      text-align: center;
      padding: 20px;
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem auto;
   }
</style>
</head>
<body>
<h1>HTML Window alert() Method</h1>
<button class='btn' onclick="add()">Click me to open an alert box</button>
<script>
   function add() {
      alert("Hello! I'm an alert box");
   }
</script>
</body>
</html>

輸出

點選“建立我以開啟警告框”按鈕以開啟一個警告框。

更新於: 26-Sep-2019

777 次瀏覽

開啟你的 事業

完成課程即可獲得認證

立即開始
廣告
© . All rights reserved.