본문 바로가기
: ) Web/웹 스터디

[JS] [실습] function 문법 | alert 박스 만들기

by miiinn 2024. 1. 5.

초기 화면
버튼1 클릭 시
버튼2 클릭 시

 

 

[HTML]

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <link rel="stylesheet" href="main.css">
    </head>
    <body>

        <div id="alert" class="alert-box">
            <p id="title">아이디를 입력하세요.</p>
            <button onclick="alert('none','close')">닫기</button>
        </div>

        <button onclick="alert('block','아이디를 입력하세요')">버튼1</button>
        <button onclick="alert('block','비밀번호를 입력하세요')">버튼2</button>

        <script>
            function alert(any, text){
                document.getElementById('alert').style.display = any;
                document.getElementById('title').innerHTML = text;
            }
        </script>


    </body>
</html>

 

[css]

.alert-box {
    background-color: skyblue;
    padding: 20px;
    color: white;
    border-radius: 5px;
    display: none;
}