HTML 창 alert() 메서드는 HTML 문서에 정의된 메시지와 확인 버튼이 있는 경고 상자를 표시합니다.
구문
다음은 구문입니다 -
alert(“message”);
HTML 창 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> 출력

'알림 상자를 열려면 내가 만들기를 클릭하세요. " 버튼을 눌러 경고 상자를 엽니다.
