aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/api/eventlistener/index.html
blob: ca59ea3c434bc4a701a3ca6cff51fd59c28944e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
title: EventListener
slug: Web/API/EventListener
translation_of: Web/API/EventListener
---
<div>{{APIRef("DOM Events")}}</div>

<p><strong><code>EventListener</code></strong> 인터페이스는 {{domxref("EventTarget")}} 객체로부터 발생한 이벤트를  처리하기 위한 오브젝트를 말합니다.</p>

<div class="note">
<p><strong>Note:</strong> 레거시 코드와의 호환성을 유지하기 위해서, <code>EventListener</code> 는 함수 혹은 <code>handleEvent()</code> 함수를 가진 오브젝트를 인자로 받습니다.  아래의 <a href="https://developer.mozilla.org/en-US/docs/Web/API/EventListener$translate?tolocale=ko#Example">예제</a>에서 확인해보세요.</p>
</div>

<h2 id="속성">속성</h2>

<p><em>이 인터페이스는 구현체나, 상속, 속성 어떤것도 갖고 있지 않습니다.</em></p>

<h2 id="메소드">메소드</h2>

<p><em>이 인터페이스는 어떤 메소드도 상속받지 않습니다.</em></p>

<dl>
 <dt>{{domxref("EventListener.handleEvent()")}}</dt>
 <dd>주어진 타입의 이벤트가 발생할 때마다 호출될 함수입니다.</dd>
</dl>

<h2 id="예제">예제</h2>

<h3 id="HTML">HTML</h3>

<pre class="brush: html">&lt;button id="btn"&gt;여기를 눌러보세요!&lt;/button&gt;</pre>

<h3 id="JavaScript">JavaScript</h3>

<pre class="brush: js">const buttonElement = document.getElementById('btn');

// 콜백 함수를 제공함으로써 '클릭' 이벤트를 처리하는 핸들러를 추가합니다.
// 엘리먼트가 클릭될 떄마다, "누름!" 팝업이 나타날것입니다.
buttonElement.addEventListener('click', function (event) {
  alert('누름!');
});

// 호환성을 위해서, 함수가 아닌 `handleEvent` 속성을 가진 오브젝트도
// 똑같이 처리됩니다.
buttonElement.addEventListener('click', {
  handleEvent: function (event) {
    alert('handleEvent 함수로 누름!');
  }
});
</pre>

<h3 id="Result">Result</h3>

<p>{{EmbedLiveSample('Example')}}</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('DOM WHATWG', '#callbackdef-eventlistener', 'EventListener')}}</td>
   <td>{{Spec2('DOM WHATWG')}}</td>
   <td>No change.</td>
  </tr>
  <tr>
   <td>{{SpecName('DOM2 Events', '#Events-EventListener', 'EventListener')}}</td>
   <td>{{Spec2('DOM2 Events')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("api.EventListener")}}</p>