質問編集履歴
1
dareさんからのご指摘いただいた部分を修正致しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -194,6 +194,200 @@
|
|
194
194
|
|
195
195
|
```
|
196
196
|
|
197
|
+
<dateさんからのご指摘をいただいた部分を修正したものになります>
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
```
|
202
|
+
|
203
|
+
<script>
|
204
|
+
|
205
|
+
try{
|
206
|
+
|
207
|
+
document.addEventListener ('click',function(e){myfunc(e)},true);
|
208
|
+
|
209
|
+
}catch(e){
|
210
|
+
|
211
|
+
document.attachEvent('onclick',function(e){myfunc(e)});
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
var cnt=0;
|
216
|
+
|
217
|
+
function myfunc(e){
|
218
|
+
|
219
|
+
var t = (e.srcElement || e.target);
|
220
|
+
|
221
|
+
if(t.nodeName=="INPUT" && t.type=="button"){
|
222
|
+
|
223
|
+
if(t.value==""){
|
224
|
+
|
225
|
+
cnt++;
|
226
|
+
|
227
|
+
t.value=cnt%2==1?"○":"×";
|
228
|
+
|
229
|
+
if(cnt>=16){
|
230
|
+
|
231
|
+
alert("引き分け(OKでリセットします)");
|
232
|
+
|
233
|
+
resetFunc(t);
|
234
|
+
|
235
|
+
cnt=0;
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
}else if( cnt > 2 ){
|
240
|
+
|
241
|
+
alert("そのマスはすでに選ばれています。");
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
if(t.nodeName=="INPUT" && t.type=="reset"){
|
248
|
+
|
249
|
+
cnt=0;
|
250
|
+
|
251
|
+
resetFunc(t);
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
function resetFunc(t){
|
258
|
+
|
259
|
+
var f=t.form;
|
260
|
+
|
261
|
+
var a=new Array();
|
262
|
+
|
263
|
+
var j=0;
|
264
|
+
|
265
|
+
for(var i=0;i<f.length;i++){
|
266
|
+
|
267
|
+
if(f[i].type=="button"){
|
268
|
+
|
269
|
+
a[j]=f[i].value;
|
270
|
+
|
271
|
+
j++;
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
if(
|
278
|
+
|
279
|
+
(a[0]!=="" && a[0]==a[1] && a[0]==a[2] && a[0]==a[3])||
|
280
|
+
|
281
|
+
(a[0]!=="" && a[0]==a[5] && a[0]==a[10] && a[0]==a[15])||
|
282
|
+
|
283
|
+
(a[0]!=="" && a[0]==a[4] && a[0]==a[8] && a[0]==a[12])||
|
284
|
+
|
285
|
+
(a[1]!=="" && a[1]==a[5] && a[1]==a[9] && a[1]==a[13])||
|
286
|
+
|
287
|
+
(a[2]!=="" && a[2]==a[6] && a[2]==a[10] && a[2]==a[14])||
|
288
|
+
|
289
|
+
(a[3]!=="" && a[3]==a[7] && a[3]==a[11] && a[3]==a[15])||
|
290
|
+
|
291
|
+
(a[3]!=="" && a[3]==a[6] && a[3]==a[9] && a[1]==a[12])||
|
292
|
+
|
293
|
+
(a[4]!=="" && a[4]==a[5] && a[4]==a[6] && a[4]==a[7])||
|
294
|
+
|
295
|
+
(a[8]!=="" && a[8]==a[9] && a[8]==a[10] && a[8]==a[11])||
|
296
|
+
|
297
|
+
(a[12]!=="" && a[12]==a[13] && a[12]==a[14] && a[12]==a[15])){
|
298
|
+
|
299
|
+
var val=cnt%2==1?"○":"×";
|
300
|
+
|
301
|
+
alert(val+"の勝ち");
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
}
|
306
|
+
|
307
|
+
function resetFunc(t){
|
308
|
+
|
309
|
+
var f=t.form;
|
310
|
+
|
311
|
+
for(var i=0;i<f.length;i++){
|
312
|
+
|
313
|
+
if(f[i].type=="button") f[i].value="";
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
</script>
|
320
|
+
|
321
|
+
</head>
|
322
|
+
|
323
|
+
<form name="tick">
|
324
|
+
|
325
|
+
<table>
|
326
|
+
|
327
|
+
<tr>
|
328
|
+
|
329
|
+
<td><input type="button"></td>
|
330
|
+
|
331
|
+
<td><input type="button"></td>
|
332
|
+
|
333
|
+
<td><input type="button"></td>
|
334
|
+
|
335
|
+
<td><input type="button"></td>
|
336
|
+
|
337
|
+
</tr>
|
338
|
+
|
339
|
+
<tr>
|
340
|
+
|
341
|
+
<td><input type="button"></td>
|
342
|
+
|
343
|
+
<td><input type="button"></td>
|
344
|
+
|
345
|
+
<td><input type="button"></td>
|
346
|
+
|
347
|
+
<td><input type="button"></td>
|
348
|
+
|
349
|
+
</tr>
|
350
|
+
|
351
|
+
<tr>
|
352
|
+
|
353
|
+
<td><input type="button"></td>
|
354
|
+
|
355
|
+
<td><input type="button"></td>
|
356
|
+
|
357
|
+
<td><input type="button"></td>
|
358
|
+
|
359
|
+
<td><input type="button"></td>
|
360
|
+
|
361
|
+
</tr>
|
362
|
+
|
363
|
+
<tr>
|
364
|
+
|
365
|
+
<td><input type="button"></td>
|
366
|
+
|
367
|
+
<td><input type="button"></td>
|
368
|
+
|
369
|
+
<td><input type="button"></td>
|
370
|
+
|
371
|
+
<td><input type="button"></td>
|
372
|
+
|
373
|
+
</tr>
|
374
|
+
|
375
|
+
</table>
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
<input type="reset" value="リセット">
|
380
|
+
|
381
|
+
</p>
|
382
|
+
|
383
|
+
</form>
|
384
|
+
|
385
|
+
</body>
|
386
|
+
|
387
|
+
```
|
388
|
+
|
389
|
+
|
390
|
+
|
197
391
|
|
198
392
|
|
199
393
|
ご教授、ご指摘の方よろしくお願いします。
|