• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 JavaScript, TS 게시판 이벤트리스너 콜백함수 파라미터넣기

이벤트리스너 콜백함수 파라미터넣기

5 글 보임 - 1 에서 5 까지 (총 5 중에서)
  • 글쓴이
  • #58721

    송원준
    참가자
     <div class="alert">
          <p class="alertBox"></p>
          <button class="closeBox">닫기</button>
        </div>
        <button class="btn1">버튼1</button>
        <button class="btn2">버튼2</button>
        <script>
          const alert = document.querySelector(".alert");
          const alertWindow = document.querySelector(".alertBox");
          const btn1 = document.querySelector(".btn1");
          const btn2 = document.querySelector(".btn2");
          const closeBox = document.querySelector(".closeBox");
          function alertWindowToggle(which) {
            if (which === "pleaseid") {
              alertWindow.innerHTML = "Please Input Your ID";
              alert.style.display = "block";
            } else if (which === "password") {
              alertWindow.innerHTML = "Please Input Your Password";
              alert.style.display = "block";
            }
          }
          function closeAlertBox() {
            alert.style.display = "none";
          }
          closeBox.addEventListener("click", closeAlertBox);
          btn1.addEventListener("click", alertWindowToggle("pleaseid"));
          btn2.addEventListener("click", alertWindowToggle("password"));
        </script>
    
    
    이렇게 하면 왜 버튼1, 버튼2 눌렀을 때 알림창이 안뜨는지 모르겠습니다..
    #58723

    송원준
    참가자
    .alert {
      display: none;
      width: 300px;
      height: 200px;
      background: skyblue;
    }
    
    CSS 파일에는 이렇게 작성되어 있습니다.
    #58770

    codingapple
    키 마스터
    .addEventListener("click", function(){
       alertWindowToggle("pleaseid")
    })
    합시다
    #59082

    송원준
    참가자
    무슨 차이가 있나요?? 똑같은거 아닌가욤?
    #59085

    codingapple
    키 마스터
    콜백함수자리에 이름있는 함수넣으려면 함수이름만 넣게 되어있어서 그렇습니다
5 글 보임 - 1 에서 5 까지 (총 5 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관, 개인정보처리방침
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠