信号作りでとりあえずstartボタンを押したら青が点灯するようにしたいのですが、うまくいきません。何が原因でしょうか?? また青を三秒間点灯させるにはforの繰り返しを使えばいいのでしょうか。。?
<DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <title>信号を作る</title> <link rel="stylesheet" href="信号.css"> </head> <body> <div id="square"> <div class="red"></div> <div class="yellow"></div> <div class="blue"></div> </div> <button id="start">START</button> <button id="stop">STOP</button> <script> window.onload=function(){ var start=document.getElementById('start'); start.addEventListener('click',tentou,false); } function tentou(){ var blue=document.getElementsByClassName('blue'); blue.style.backgroundColor='blue'; } </script> </body> </html> //css #square{ border:solid 1px black; width:700px; height:200px; margin: auto; position:absolute; top:0; bottom:0; left:0; right:0; } .red,.yellow,.blue{ width:150px; height:150px; border-radius:50%; border:solid 1px black; float:left; }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。