-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent2.html
46 lines (44 loc) · 1.11 KB
/
event2.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<style>
.wrapper{
height: 40px;
border: 1px solid red;
}
</style>
<body>
<div class='wrapper'>
<button>click me</button>
</div>
<script>
function print(e){
let currentTarget = e.currentTarget
switch(e.eventPhase){
case 1:
console.log(currentTarget,':CAPTURING_PHASE')
break
case 2:
console.log(currentTarget,':AT_TARGET')
break
case 3:
console.log(currentTarget,':BUBBLING_PHASE')
break
case 0:
console.log(currentTarget,':NONE')
break
default:
throw new TypeError('what happened')
}
}
const $wrapper = document.querySelector('.wrapper')
const $button = document.querySelector('button')
$wrapper.addEventListener('click',print,false)
$wrapper.addEventListener('click',print,false)
$wrapper.addEventListener('click',print,true)
</script>
</body>
</html>