<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> body,dl,dt,dd,p{ margin:0; padding:0; } body{ font-family:Tahoma; font-size:12px; } div{ width: 250px; height: 80px; background: #333; margin: 10px auto; color: #000; font-size: 16px; text-align: center; padding: 10px 0; } input{ margin: 10px; width: 30px; height: 20px; text-align: center; line-height: 20px; font-size: 16px; } span{ color: #fff; font-size: 16px; } button{ display: block; width: 200px; height: 30px; margin: 0px auto; } </style> </head> <body> <div id="outer"> <input type="text" value="0" /><span>分钟</span> <input type="text" value="60" /><span>秒</span> <button>启动</button> </div> <script type="text/javascript"> var oInput = document.getElementsByTagName('input'); var oBtn = document.getElementsByTagName('button')[0]; var i=1; function timeOclock (){ if( i == 1){ return; } if( i == -1 ){ var getMin = parseInt(oInput[0].value)*60; var getSec = parseInt(oInput[1].value); if(oInput[0].value == 0 && oInput[1].value == 0){ return; } var total = getMin + getSec - 1; var min = parseInt(total / 60); var sec = total-(min*60); oInput[0].value = min; oInput[1].value = sec; } } oBtn.onclick = function(){ i *= -1; if(i == -1){ oBtn.innerHTML = '取消'; setInterval(timeOclock,1000); } if(i == 1){ oBtn.innerHTML = '点击'; } } </script> </body> </html>
求大神看看,为什么暂停计时后再重新开始计时就加快了?谢谢了
慕码人5092043
小感冒
相关分类