-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.html
59 lines (59 loc) · 1.77 KB
/
event.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
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.wrap {
position: relative;
background-color: antiquewhite;
width: 200px;
height: 200px;
}
.sub1 {
position: absolute;
left: 20px;
top: 20px;
background-color: rebeccapurple;
width: 160px;
height: 160px;
}
.sub2 {
position: absolute;
left: 20px;
top: 20px;
background-color: royalblue;
width: 120px;
height: 120px;
}
</style>
</head>
<body>
<div id="wrap" class="wrap" onclick="didClicked()">
<div id="sub1" class="sub1" onclick="didClicked1()">
<div id="sub2" class="sub2" onclick="didClicked2()"></div>
</div>
</div>
<script>
// https://stackoverflow.com/questions/4616694/what-is-event-bubbling-and-capturing
// https://www.quirksmode.org/js/events_order.html
// preventDefault
// stopPropagation
document.body.addEventListener('click', (e) => {
console.log('click body');
}, true);
document.getElementById('wrap').addEventListener('click', (e) => {
console.log('click wrap');
// e.stopPropagation();
}, true);
document.getElementById('sub1').addEventListener('click', (e) => {
console.log('click sub1');
}, true);
document.getElementById('sub2').addEventListener('click', (e) => {
console.log('click sub2');
// e.stopPropagation();
}, true);
</script>
</body>
</html>