0

ストップウォッチ機能を作成する次のコードがあります。私がしたいのは、開始と停止ボタンを開始と一時停止にすることだけです。しかし、私はこれを行う方法を見つけようとして、インターネットで頭を悩ませてきました。どんな助けでも大歓迎です。ありがとう!

<script type="text/javascript">
<!-- Stopwatch
    var stopwatch;
    var runningstate = 0; // 1 means the timecounter is running 0 means counter stopped
    var stoptime = 0;
    var lapcounter = 0;
    var currenttime;
    var lapdate = '';


function timecounter(starttime)
        {
        currentdate = new Date();
        stopwatch = document.getElementById('stopwatch');
        var timediff = currentdate.getTime() - starttime;
        if(runningstate == 0)
            {
            timediff = timediff + stoptime
            }
        if(runningstate == 1)
            {
            stopwatch.value = formattedtime(timediff);
            refresh = setTimeout('timecounter(' + starttime + ');',10);
            }
        else
            {
            window.clearTimeout(refresh);
            stoptime = timediff;
            }
        }


function marklapH()
             {
             if(runningstate == 1)
                   {
                   if(lapdate != '')
                       {
                        var lapold = lapdate.split(':');
                        var lapnow = stopwatch.value.split(':');
                        var lapcount = new Array();
                        var x = 0
        for(x; x < lapold.length; x++)
             {
         lapcount[x] = new Array();
         lapcount[x][0] = lapold[x]*1;
         lapcount[x][1] = lapnow[x]*1;
              }
         if(lapcount[1][1] < lapcount[1][0])
              {
            lapcount[1][1] += 60;
              lapcount[0][1] -= 1;
             }
          if(lapcount[2][1] < lapcount[2][0])
             {
             lapcount[2][1] += 10;
             lapcount[1][1] -= 1;
              }
         }
       lapdate = stopwatch.value;
       Hlapdetails.value += (++lapcounter) + '. ' + stopwatch.value + '\n';
        }
     }


function startandstop()
      {
      var startandstop = document.getElementById('startandstopbutton');
      var startdate = new Date();
      var starttime = startdate.getTime();
      if(runningstate==0)
    {
     startandstop.value = 'Stop';
     runningstate = 1;
     timecounter(starttime);
     }
 else
      {
      startandstop.value = 'Start';
      runningstate = 0;
      lapdate = '';
      }
   }


function resetstopwatch()
        {
      lapcounter = 0;
      stoptime = 0;
      lapdate = '';
      window.clearTimeout(refresh);
     if(runningstate == 1)
   {
   var resetdate = new Date();
   var resettime = resetdate.getTime();
   timecounter(resettime);
  }
else
  {
    stopwatch.value = "0:0:0";
  }
 }


function formattedtime(unformattedtime)
  { 
   var decisec = Math.floor(unformattedtime/100) + '';
   var second = Math.floor(unformattedtime/1000);
    var minute = Math.floor(unformattedtime/60000);
decisec = decisec.charAt(decisec.length - 1);
second = second - 60 * minute + '';
return minute + ':' + second + ':' + decisec;
}
</script>
4

1 に答える 1