以下のプログラムの時、CSSで
・○の時は○の色は白、背景色は黄色
・×の時は×の色は黄色、背景色は青
としたいです。
どのようにおいたらいいのでしょうか?
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <link rel="stylesheet" type="text/css" href="css/index.css"> <title>○×ゲーム</title> </head> <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("そのマスはすでに選ばれています。"); } } 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> <body> <form name="tick"> <table> <tr> <td><input type="button" id="botan"></td> <td><input type="button" id="botan"></td> <td><input type="button" id="botan"></td> </tr> <tr> <td><input type="button" id="botan"></td> <td><input type="button" id="botan"></td> <td><input type="button" id="botan"></td> </tr> <tr> <td><input type="button" id="botan"></td> <td><input type="button" id="botan"></td> <td><input type="button" id="botan"></td> </tr> </p> </table> <input type="reset" id="riset" value="リセット"> </p> </form> </body>
@charset "utf-8"; #botan{ width: 50px; height: 50px; margin: 3px; font-size: 30pt; background-color: black; } #riset{ font-size: 20x;
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー