暂停和重启按钮不起作用

时间:2017-06-08 07:43:24

标签: javascript mysql

我正在使用javascript来启动和停止计时器(秒表)。我想要的是当用户按下停止按钮时, 数据(当时的时间)将存储在我的MySQL数据库中。但我的暂停按钮不起作用..

function stopwatch(text) {
   var d = new Date();
   var h = d.getHours();
   var m = d.getMinutes();
   var s = d.getSeconds();
   var ms = d.getMilliseconds();
   document.stopwatchclock.stpwtch.value = +h + " : " + m + " : " + s + " : " + ms;

   SD = window.setTimeout("stopwatch();", 100);
   theResult = document.stopwatchclock.stpwtch.value;
 }

 function resetIt() {

   if (document.stopwatchclock.stopreset.value == "Pause") {
     stopResult = document.stopwatchclock.stpwtch.value;
     window.clearTimeout(stopResult);
   }
   if (document.stopwatchclock.stopreset.value == "Pause") {
     document.stopwatchclock.stopreset.value = "Restart";
   }
 }



center {
  width: 50%;
  margin-left: 25%;
}

.mainblock {
  background-color: #07c1cc;
}

.stopWatchClass {
  background-color: #07c1cc;
  display: block;
}

#stopwatchclock input {
  margin-bottom: 10px;
  width: 120px;
}
<html>
<head>
    <title>Stopwatch Application ( Using JAVASCRIPT + HTML + CSS )</title>


</head>
<body>
    <center>
        <div class="mainblock">
            <h1><b title="Stopwatch Application ( Using JAVASCRIPT + HTML + CSS )">Stopwatch Application</b></h1>
            <form name="stopwatchclock" id="stopwatchclock">
                <input type="text" size="16" class="" name="stpwtch" value=" 00 : 00 : 00 : 00" title="Initially blank" />
                <input type="button" name="theButton" id="start" onClick="stopwatch();" value="Start" title="The 'START' button is start the stopwatch. An already started stopwatch cannot be started again." /><br />
                <div id="morefeature">
                    <input type="button" name="stopreset" value="Pause" id="Pause" onClick="resetIt(this.value);" title="Once you will click on 'RESET' button will entirely reset the stopwatch so that it can be started again." />

                    <div>

            </form>
        </div>
        <div id="stopwatchresult"></div>
    </center>
</body>

1 个答案:

答案 0 :(得分:0)

切换到:

window.clearTimeout(SD);

而不是:

window.clearTimeout(stopResult);