HTML DOM - key 이벤트

이시원·2022년 7월 10일

바닐라 JS - 기타

목록 보기
5/7
post-thumbnail

key 이벤트

<!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>
  </head>
  <body>
    <input
      type="text"
      onkeypress="myFunction(event)"
      onkeydown="myFunction(event)"
      onkeyup="myFunction(event)"
    />
    <script>
      function myFunction(e) {
        console.log(e.type); // 이벤트 이름 출력
        console.log(e.target); // 이벤트를 발생시킨 DOM Element(요소)
        console.log(e.target.value); // 이벤트가 일어나는 시점에 입력된 값이 어떻게 변하는지 출력
      }
    </script>
  </body>
</html>


profile
코딩공부

0개의 댓글