หน้าต่าง HTML alert() วิธีการแสดงกล่องแจ้งเตือนพร้อมข้อความที่กำหนดและปุ่มตกลงในเอกสาร HTML
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
alert(“message”);
ให้เราดูตัวอย่างของ HTML window alert() method -
ตัวอย่าง
<!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> ผลลัพธ์

คลิกที่ “สร้างฉันเพื่อเปิดกล่องแจ้งเตือน ” เพื่อเปิดกล่องแจ้งเตือน
