저장을 습관화

강의 추천 - 코딩애플, 웹개발로 배우는 자바스크립트 기초 본문

공부/메모

강의 추천 - 코딩애플, 웹개발로 배우는 자바스크립트 기초

ctrs 2023. 6. 6. 21:11

- 오늘 보게된 자바스크립트 기초 강의

재밌고 유용하니 다른 사람들에게도 추천하고 싶다

6편 기본 제공이고, 나머지는 결제 후 수강이다.

 

기본 제공 강의 6편으로 selector와 function, getElementById, addEventListener 실습도 가능하니 

나중에 헷갈리면 다시 보기 위해 메모한다.

 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .alert-box {
        background: lightblue;
        color: blue;
        padding: 20px;
        border-radius: 5px;
        display: none;
      }
    </style>
  </head>
  <body>
    <div class="alert-box" id="alertBox">
      <span id="boxMsg">메세지에요</span>
      <button id="boxClose">닫기 버튼</button>
    </div>

    <button onclick="divCon('block', 'ID 입력안했어요')">ID 버튼</button> 
    <button onclick="divCon('block', 'PW 입력안했어요')">PW 버튼</button>
    // 위 두줄의 'block', '~입력안했어요'가 argument, 전달인자이고

    <script>
      function divCon(how, what) { // 여기서 how와 what이 parameter, 매개변수이다.
        document.getElementById("alertBox").style.display = how;
        document.getElementById("boxMsg").innerHTML = what; 
      }

      document
        .getElementById("boxClose")
        .addEventListener("click", function () {
          document.getElementById("alertBox").style.display = "none";
        });
    </script>
  </body>
</html>

 

낮에는 딴 생각만 들었는데 해가 지면 공부에 집중이 더 잘되는건 왜일까