-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path09.html
57 lines (51 loc) · 1.2 KB
/
09.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
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8' />
<title>DOM EXAMPLE</title>
<script>
function hide(e) {
e.innerHTML = "X";
}
function show(...e) {
e.forEach(e => {
e.innerHTML = e.id;
});
}
var buttons = [];
function toggle(e) {
hide(e);
switch(e.id) {
case 'A':
show(buttons[1], buttons[0]);
break;
case 'B':
show(buttons[2], buttons[0]);
break;
case 'C':
show(buttons[2], buttons[1]);
break;
};
}
function newButton(id) {
let b = document.createElement("BUTTON");
b.id = id;
b.onclick = new Function("toggle(this);");
b.appendChild(document.createTextNode(id));
return b;
}
window.onload = () => {
let button_bar = document.getElementById("action_buttons");
['A', 'B', 'C'].forEach(n => {
buttons.unshift(newButton(n));
button_bar.appendChild(buttons[0]);
});
};
</script>
</head>
<body>
<h1>DOM EXAMPLE</h1>
<h2>Known Actions</h2>
<div id="action_buttons"></div>
</body>
</html>