forked from jackfrued/Python-100-Days
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample06.html
41 lines (41 loc) · 942 Bytes
/
example06.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1 id="message">Hello, world!</h1>
<button id="btn">0</button>
<script>
var counter = 0;
var btn = document.getElementById('btn');
var h1 = document.getElementById('message');
function f1() {
alert('按钮被点击了!');
if (btn.removeEventListener) {
btn.removeEventListener('click', f1);
} else {
btn.detachEvent('onclick', f1);
}
}
function f2() {
counter += 1;
btn.textContent = counter;
}
function f3() {
h1.textContent = 'Goodbye, world!';
}
if (btn.addEventListener) {
btn.addEventListener('click', f1);
btn.addEventListener('click', f2);
btn.addEventListener('click', f3);
} else {
// 低版本IE浏览器
btn.attachEvent('onclick', f1);
btn.attachEvent('onclick', f2);
btn.attachEvent('onclick', f3);
}
</script>
</body>
</html>