回答編集履歴

2

追加

2016/07/26 00:34

投稿

date
date

スコア1820

test CHANGED
@@ -7,3 +7,269 @@
7
7
 
8
8
 
9
9
  さらにif文の最後が)で閉じられていないです。
10
+
11
+
12
+
13
+ 2016/07/26 09:30追記
14
+
15
+ ```javascript
16
+
17
+ <script>
18
+
19
+ try{
20
+
21
+ document.addEventListener ('click',function(e){myfunc(e)},true);
22
+
23
+ }catch(e){
24
+
25
+ document.attachEvent('onclick',function(e){myfunc(e)});
26
+
27
+ }
28
+
29
+ var cnt=0;
30
+
31
+ function myfunc(e){
32
+
33
+ var t = (e.srcElement || e.target);
34
+
35
+ if(t.nodeName=="INPUT" && t.type=="button"){
36
+
37
+ if(t.value==""){
38
+
39
+ cnt++;
40
+
41
+ t.value=cnt%2==1?"○":"×";
42
+
43
+
44
+
45
+ if(cnt>=16){
46
+
47
+ alert("引き分け(OKでリセットします)");
48
+
49
+ resetFunc(t);
50
+
51
+ cnt=0;
52
+
53
+ }else{
54
+
55
+ Func(t);
56
+
57
+ }
58
+
59
+ }else if( cnt > 2 ){
60
+
61
+ alert("そのマスはすでに選ばれています。");
62
+
63
+ }
64
+
65
+ }
66
+
67
+ if(t.nodeName=="INPUT" && t.type=="reset"){
68
+
69
+ cnt=0;
70
+
71
+ resetFunc(t);
72
+
73
+ }
74
+
75
+ }
76
+
77
+ function Func(t){
78
+
79
+
80
+
81
+ var f=t.form;
82
+
83
+ var a=new Array();
84
+
85
+ var j=0;
86
+
87
+ for(var i=0;i<f.length;i++){
88
+
89
+ if(f[i].type=="button"){
90
+
91
+ a[j]=f[i].value;
92
+
93
+ j++;
94
+
95
+ }
96
+
97
+ }
98
+
99
+ console.log(a);
100
+
101
+ if(
102
+
103
+ (a[0]!=="" && a[0]==a[1] && a[0]==a[2] && a[0]==a[3])||
104
+
105
+ (a[0]!=="" && a[0]==a[5] && a[0]==a[10] && a[0]==a[15])||
106
+
107
+ (a[0]!=="" && a[0]==a[4] && a[0]==a[8] && a[0]==a[12])||
108
+
109
+ (a[1]!=="" && a[1]==a[5] && a[1]==a[9] && a[1]==a[13])||
110
+
111
+ (a[2]!=="" && a[2]==a[6] && a[2]==a[10] && a[2]==a[14])||
112
+
113
+ (a[3]!=="" && a[3]==a[7] && a[3]==a[11] && a[3]==a[15])||
114
+
115
+ (a[3]!=="" && a[3]==a[6] && a[3]==a[9] && a[1]==a[12])||
116
+
117
+ (a[4]!=="" && a[4]==a[5] && a[4]==a[6] && a[4]==a[7])||
118
+
119
+ (a[8]!=="" && a[8]==a[9] && a[8]==a[10] && a[8]==a[11])||
120
+
121
+ (a[12]!=="" && a[12]==a[13] && a[12]==a[14] && a[12]==a[15])){
122
+
123
+ var val=cnt%2==1?"○":"×";
124
+
125
+ alert(val+"の勝ち");
126
+
127
+ }
128
+
129
+ }
130
+
131
+ function resetFunc(t){
132
+
133
+ var f=t.form;
134
+
135
+ for(var i=0;i<f.length;i++){
136
+
137
+ if(f[i].type=="button") f[i].value="";
138
+
139
+ }
140
+
141
+ }
142
+
143
+
144
+
145
+ </script>
146
+
147
+ </head>
148
+
149
+ <form name="tick">
150
+
151
+ <table>
152
+
153
+ <tr>
154
+
155
+ <td>
156
+
157
+ <input type="button">
158
+
159
+ </td>
160
+
161
+ <td>
162
+
163
+ <input type="button">
164
+
165
+ </td>
166
+
167
+ <td>
168
+
169
+ <input type="button">
170
+
171
+ </td>
172
+
173
+ <td>
174
+
175
+ <input type="button">
176
+
177
+ </td>
178
+
179
+ </tr>
180
+
181
+ <tr>
182
+
183
+ <td>
184
+
185
+ <input type="button">
186
+
187
+ </td>
188
+
189
+ <td>
190
+
191
+ <input type="button">
192
+
193
+ </td>
194
+
195
+ <td>
196
+
197
+ <input type="button">
198
+
199
+ </td>
200
+
201
+ <td>
202
+
203
+ <input type="button">
204
+
205
+ </td>
206
+
207
+ </tr>
208
+
209
+ <tr>
210
+
211
+ <td>
212
+
213
+ <input type="button">
214
+
215
+ </td>
216
+
217
+ <td>
218
+
219
+ <input type="button">
220
+
221
+ </td>
222
+
223
+ <td>
224
+
225
+ <input type="button">
226
+
227
+ </td>
228
+
229
+ <td>
230
+
231
+ <input type="button">
232
+
233
+ </td>
234
+
235
+ </tr>
236
+
237
+ <tr>
238
+
239
+ <td>
240
+
241
+ <input type="button">
242
+
243
+ </td>
244
+
245
+ <td>
246
+
247
+ <input type="button">
248
+
249
+ </td>
250
+
251
+ <td>
252
+
253
+ <input type="button">
254
+
255
+ </td>
256
+
257
+ <td>
258
+
259
+ <input type="button">
260
+
261
+ </td>
262
+
263
+ </tr>
264
+
265
+ </table>
266
+
267
+ <input type="reset" value="リセット">
268
+
269
+ </p>
270
+
271
+ </form>
272
+
273
+ </body>
274
+
275
+ ```

1

修正

2016/07/26 00:33

投稿

date
date

スコア1820

test CHANGED
@@ -3,3 +3,7 @@
3
3
  (a[0]!=="" && a[0]==a[1] && a[0]==a[2] && a[0]==a[3])||||
4
4
 
5
5
  あきらかに ||の数がおかしいです、ほかの所も||の数がおかしいので要素の調査のなどを使えばすぐ出てくるので、見てみてください
6
+
7
+
8
+
9
+ さらにif文の最後が)で閉じられていないです。