본문 바로가기

국비필기노트/HTML & CSS & JS

js_mouse(Event)

click 클릭했을 때 발생
dblclick 더블 클릭했을 때 발생
mousedown 마우스를 누를 때 발생
mouseup 마우스버튼을 땔 때 발생
mousemove 마우스를 움직일 때 발생
mouseover 마우스가 엘리멘트에 진입할 때 발생
mouseout 마우스가 엘리멘트에 빠져나갈 때 발생
contextmenu 컨텍스트 메뉴가 실행될 때 발생

 

예시

 

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
<div id="target"></div>
<table>
<tr>
    <td>event type</td>
    <th>info</th>
</tr>
 
<tr>
    <td>click</td>
    <td id = "elmclick"></td>
</tr>
 
<tr>
    <td>dblclick</td>
    <td id = "=elmdblclick"></td>
</tr>
 
<tr>
<td>mousedown</td>
    <td id = "elmmousedown"></td>
</tr>
 
<tr>
<td>mouseup</td>
    <td id = "elmmouseup"></td>
</tr>
 
<tr>
<td>mousemove</td>
    <td id = "elmmousemove"></td>
</tr>
 
<tr>
<td>mouseover</td>
    <td id = "elmmouseover"></td>
</tr>
 
<tr>
<td>mouseout</td>
    <td id = "elmmouseout"></td>
</tr>
</table>
 
<script>
    let t = document.getElementById("target");
    
    t.addEventListener('click',handler);
    t.addEventListener('dblclick',handler);
    t.addEventListener('mousedown',handler);
    t.addEventListener('mouseup',handler);
    t.addEventListener('mousemove',handler);
    t.addEventListener('mouseover',handler);
    t.addEventListener('mouseout',handler);
    t.addEventListener('contextmenu',handler);
    
    function handler(event){
        console.log('----------------------');
        console.log(event.type);    
    }
        
</script>
cs

'국비필기노트 > HTML & CSS & JS' 카테고리의 다른 글

JS_cursor,submit(Event)  (0) 2022.05.24
JS_기본동작의 취소(Event)  (0) 2022.05.24
JS_onclick(Event)  (0) 2022.05.18
JS_document.getElementsByTagName  (0) 2022.05.16
JS_객체(Window, Location, History, Navigator)  (0) 2022.05.16