回答編集履歴
3
タイポミス
test
CHANGED
@@ -92,11 +92,9 @@
|
|
92
92
|
|
93
93
|
<body>
|
94
94
|
|
95
|
-
<div
|
95
|
+
<div id="D"></div>
|
96
96
|
|
97
97
|
<script>
|
98
|
-
|
99
|
-
|
100
98
|
|
101
99
|
|
102
100
|
|
@@ -154,11 +152,9 @@
|
|
154
152
|
|
155
153
|
e.remove ();
|
156
154
|
|
157
|
-
p = null;
|
158
|
-
|
159
155
|
}
|
160
156
|
|
161
|
-
|
157
|
+
p = null;
|
162
158
|
|
163
159
|
}
|
164
160
|
|
@@ -172,8 +168,4 @@
|
|
172
168
|
|
173
169
|
</script>
|
174
170
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
171
|
```
|
2
基本的なコードかな?短いので理解しやすいでしょう!
test
CHANGED
@@ -55,3 +55,125 @@
|
|
55
55
|
</script>
|
56
56
|
|
57
57
|
```
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
骨格としてはこんな感じ。実験用として数字をあえて表示しています。
|
62
|
+
|
63
|
+
同じ数字を2つクリックするとそれらが消えていきます。
|
64
|
+
|
65
|
+
まずは流れを理解するところから。
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
```js
|
70
|
+
|
71
|
+
<!DOCTYPE html><html>
|
72
|
+
|
73
|
+
<head><meta charset="UTF-8">
|
74
|
+
|
75
|
+
<style>
|
76
|
+
|
77
|
+
#D div {
|
78
|
+
|
79
|
+
display: inline-block;
|
80
|
+
|
81
|
+
border: 1px green solid;
|
82
|
+
|
83
|
+
width: 30px;
|
84
|
+
|
85
|
+
height: 30px;
|
86
|
+
|
87
|
+
text-align: center;
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
</style>
|
92
|
+
|
93
|
+
<body>
|
94
|
+
|
95
|
+
<div class="card_zone" id="D"></div>
|
96
|
+
|
97
|
+
<script>
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
const
|
104
|
+
|
105
|
+
N = 25,
|
106
|
+
|
107
|
+
NIGO = [...Array(N).keys(), ...Array(N).keys()],
|
108
|
+
|
109
|
+
LEN = NIGO.length,
|
110
|
+
|
111
|
+
R = n=> Math.random () * n|0;
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
[...D.children].forEach (e=> e.remove ());
|
116
|
+
|
117
|
+
let template = document.createElement ('div');
|
118
|
+
|
119
|
+
template.classList.add ('card');
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
for (let n of NIGO) {
|
124
|
+
|
125
|
+
let d = D.appendChild (template.cloneNode (true));
|
126
|
+
|
127
|
+
d.dataset.num = n;
|
128
|
+
|
129
|
+
d.textContent = n;//これは必要ない
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
for (let i = LEN; i; i--)
|
136
|
+
|
137
|
+
D.appendChild (D.children[R(i)]);
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
let p;
|
142
|
+
|
143
|
+
function handler (event) {
|
144
|
+
|
145
|
+
let e = event.target;
|
146
|
+
|
147
|
+
if (! p) return p = e;
|
148
|
+
|
149
|
+
if (p == e) return;
|
150
|
+
|
151
|
+
if (p.dataset.num == e.dataset.num) {
|
152
|
+
|
153
|
+
p.remove ();
|
154
|
+
|
155
|
+
e.remove ();
|
156
|
+
|
157
|
+
p = null;
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
else p = n = null;
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
D.addEventListener('click', handler, false);
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
</script>
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
```
|
1
カッコつけた
test
CHANGED
@@ -42,7 +42,7 @@
|
|
42
42
|
|
43
43
|
if (! A.has (e))
|
44
44
|
|
45
|
-
(e.textContent = wariate[i], A.add (e));
|
45
|
+
((e.textContent = wariate[i]), A.add (e));
|
46
46
|
|
47
47
|
}
|
48
48
|
|