以下のプログラムで各マスにおいて一度クリックしたマスをもう一度クリックするとアラート文が表示したいのですがどのようにプログラムを組めばいいんでしょう?
今のプログラムだと全体で2回以上クリックするとアラート文が表示されてしまう状態です。
<script> try{ document.addEventListener ('click',function(e){myfunc(e)},true); }catch(e){ document.attachEvent('onclick',function(e){myfunc(e)}); } var cnt=0; function myfunc(e){ var t = (e.srcElement || e.target); if(t.nodeName=="INPUT" && t.type=="button"){ if(t.value==""){ cnt++; t.value=cnt%2==1?"○":"×"; if(cnt>=9){ alert("GAMEOVER!(OKでリセットします)"); resetFunc(t); cnt=0; }else if(cnt >=2){ alert("no!"); } } } if(t.nodeName=="INPUT" && t.type=="reset"){ cnt=0; resetFunc(t); } } function resetFunc(t){ var f=t.form; for(var i=0;i<f.length;i++){ if(f[i].type=="button") f[i].value=""; } } </script> </head> <form name="tick"> <table> <tr> <td><input type="button"></td> <td><input type="button"></td> <td><input type="button"></td> </tr> <tr> <td><input type="button"></td> <td><input type="button"></td> <td><input type="button"></td> </tr> <tr> <td><input type="button"></td> <td><input type="button"></td> <td><input type="button"></td> </tr> </table> <input type="reset" value="リセット"> </p> </form> </body>
よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/13 10:18
2016/06/13 10:22
2016/06/13 10:29
2016/06/13 10:31
2016/06/13 10:32
2016/06/13 10:33
2016/06/13 10:35