728x90
반응형
<!DOCTYPE html>
<html lang="ko">
    <head>
        <title>이벤트</title>
            <meta charset="UTF-8">
            <meta http-equiv="x-uv-compatible">
    </head>
    <body>
        <div id="button">Click!</div>
        <script>
            // 선택된 요소 .addEventListener(이벤트 종료, 함수)
            let buttonElement = window.document.getElementById('button');
            buttonElement.addEventListener('click', () => {
                alert('hello');
                // alert('hello');
                // alert(x); x라는 내용을 가지는 메세지 출력
                if (confirm('Really?')) {
                    alert('yes');
                    // confirm(x) x라는 내용을 가지는 메세지를 출력하나 [확인]클릭시 true, [취소]클릭시 false를 반환한다.
                     }
                else{
                    alert('no');
                }
            });


        </script>
    </body>
</html>
728x90
반응형

'코딩일지 > WEB' 카테고리의 다른 글

함수(let)  (2) 2022.12.25
조건문  (0) 2022.12.25
요소선택  (2) 2022.12.25
오브젝트(키-값)  (0) 2022.12.25
연산자  (0) 2022.12.25

+ Recent posts

">