javascriptで動くストップウォッチを作ったのですが、STARTボタンを押してもスタートしません。
どこかにミスがあるはずなのですが、自力で見つけることができませんでした・・。
どなたか、ご指南ください。
よろしくお願いいたします。
javascript,html,css
1 2<!DOCTYPE html> 3<html lang="ja"> 4<head> 5 <meta charset="utf-8"> 6 <title>Stop Watch</title> 7 <style> 8 body { 9 background: #e0e0e0; 10 font-family: Arial, sans-serif; 11 text-align: center; 12 13 } 14 #timerText { 15 color: #00aaff; 16 font-size: 128px; 17 margin: 40px auto; 18 text-shadow: 0 1px rgba(255, 255, 255, 0.5); 19 } 20 21 22 </style> 23</head> 24<body> 25 <div id="timerText">0.00</div> 26 <button id="start">START</button> 27 <button id="stop">STOP</button> 28 <button id="reset">RESET</button> 29 <script> 30 (function(){ 31 'use strict'; 32 33 var = startTime; 34 var = timerId; 35 36 var startButton = document.getElementById('start'); 37 var stopButton = document.getElementById('stop'); 38 var resetButton = document.getElementById('reset'); 39 var timerText = document.getElementById('timerText'); 40 41 startButton.addEventListener('click', function(){ 42 startTime = Date.now(); 43 updateTimerText(); 44 }); 45 46 function updateTimerText(){ 47 timerId = setTimeout(function(){ 48 var t = Date.now() - startTime; 49 timerText.innerHTML = (t / 1000).toFixed(2); 50 updateTimerText(); 51 }, 10); 52 }; 53 54 })(); 55 </script> 56</body> 57</html> 58
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/04 01:35