[코딩애플] 실용 자바스크립트 2강 : Alert 만들어서 유저 위협하기

2023. 1. 22. 01:58언어(Language)/Javascript

UI 만드는 법

1. 미리 디자인 해놓고 숨김

2. 원할 때 JS를 이용해서 보여줌

 

수업)

[codingApple.html]

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="codingApple.css">
</head>
<body>
    <div class="alert-box" id="alert">Alert 박스</div>
    <button onclick="document.getElementById('alert').style.display = 'block';">버튼</button>
    
    <script>
        
    </script>
</body>
</html>

 

[codingApple.css]

.alert-box {
    background: #aba8f4;
    color: #4646b4;
    padding: 20px;
    border-radius: 5px;
    display: none;
}

 

 

 

숙제 : 닫기버튼 기능 개발하기

 

내 답)

[codingApple.html]

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="codingApple.css">
</head>
<body>
    <div class="alert-box" id="alert">Alert 박스</div>
    <button onclick="document.getElementById('alert').style.display = 'block';">open
    </button>
    <button onclick="document.getElementById('alert').style.display='none'">close</button>
    <script>
        
    </script>
</body>
</html>

[codingApple css]

.alert-box {
    background: #aba8f4;
    color: #4646b4;
    padding: 20px;
    border-radius: 5px;
    display: none;
}

 

 

 

 

유튜브 답)

[codingApple.html]

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="codingApple.css">
</head>
<body>
    <div class="alert-box" id="alert">
        <p>Alert 박스</p>
        <button onclick="document.getElementById('alert').style.display='none';">닫기</button>
    </div>
    <button onclick="document.getElementById('alert').style.display='block'">버튼</button>
    <script>
        
    </script>
</body>
</html>

[codingApple.css]

.alert-box {
    background: #aba8f4;
    color: #4646b4;
    padding: 20px;
    border-radius: 5px;
    display: none;
}