关于#javascript#的问题:1.在页面上实现一个秒表 00:00:00 (分钟:秒钟:百分秒) , 通过三个按钮(开始、停止、重置)来控制

    <p id = "second_watch">00:00:00</p>
    <p>
        <input id = "time_start" type = "button" value = "开始" onclick = "time_start()" /> 
        <input type="button" value="停止" onclick="time_stop()"/>
        <input type="button" value="重置" onclick="time_reset()"/>
    </p>
  <script>
    var i1 = 0;
    var i2 = 0;
    var s1 = 0;
    var s2 = 0;
    var ms1 = 0;
    var ms2 = 0;
    var t;
    
    function time_start)(){
        document.getElementByld("time_start").disabled = "true";
        ms2++;
        if(ms2>9){
            ms2 = 0;
            ms1++;
        }
        if(ms1>9){
            ms1 = 0;
            s2++;
        }
        if(s2>9){
            s2 = 0;
            s1++;
        }
        if(s1>5){
            s1 = 0;
            i2++;
        }
        if(i2>9){
            i2 = 0;
            i1++;
        }
        if(i1>5){
            //超出秒表计数范围
            clearTimeout(t);
            return false;
        }
        document.getElementByld("second_watch").innerHTML = ""+i1+i2+":"+s1+s2+":"+ms1+ms2+"";
        document.getElementByld("second_watch").style.color = "black";
        t = setTimeout("time_start()",10);
    }
        function time_stop(){
            clearTimeout(t);
            document.getElementById("second_watch").style.color = "red";
            document.getElementById("time_start").disbled = "";
        }
        function time_reset(){
                clearTimeout(t);
                i1 = 0;
                i2 = 0;
                s1 = 0;
                s2 = 0;
                ms1 = 0;
                ms2 = 0;
                document.getElementByld("second_watch").innerHTML = "" + i1 + i2 + "" +s1 + s2 + ":" + ms1 + ms2 + "" ;
                document.getElementByld("second_watch").style.color = "black";
                document.getElementById("time_start").disabled="";
        }
</script>
</body>

显示 分:秒.毫秒

<!DOCTYPE html>
<html>
<head>
  <title>秒表</title>
  <style>
    #second_watch {
      font-size: 24px;
      font-weight: bold;
      margin-bottom: 10px;
    }
  </style>
</head>
<body>
  <p id="second_watch">00:00.000</p>
  <p>
    <button id="time_start" onclick="startTimer()">开始</button>
    <button id="time_stop" onclick="stopTimer()">停止</button>
    <button id="time_reset" onclick="resetTimer()">重置</button>
  </p>

  <script>
    var timerInterval;
    var minutes = 0;
    var seconds = 0;
    var milliseconds = 0;

    function updateTimer() {
      milliseconds += 10;
      if (milliseconds >= 1000) {
        milliseconds = 0;
        seconds++;
        if (seconds >= 60) {
          seconds = 0;
          minutes++;
        }
      }

      var timeString = formatTime(minutes) + ":" + formatTime(seconds) + "." + formatMilliseconds(milliseconds);
      document.getElementById("second_watch").textContent = timeString;
    }

    function startTimer() {
      document.getElementById("time_start").disabled = true;
      document.getElementById("time_stop").disabled = false;
      document.getElementById("time_reset").disabled = false;
      timerInterval = setInterval(updateTimer, 10);
    }

    function stopTimer() {
      document.getElementById("time_start").disabled = false;
      document.getElementById("time_stop").disabled = true;
      clearInterval(timerInterval);
    }

    function resetTimer() {
      document.getElementById("time_start").disabled = false;
      document.getElementById("time_stop").disabled = true;
      document.getElementById("time_reset").disabled = true;
      clearInterval(timerInterval);
      minutes = 0;
      seconds = 0;
      milliseconds = 0;
      document.getElementById("second_watch").textContent = "00:00.000";
    }

    function formatTime(time) {
      return time < 10 ? "0" + time : time;
    }

    function formatMilliseconds(milliseconds) {
      if (milliseconds < 10) {
        return "00" + milliseconds;
      } else if (milliseconds < 100) {
        return "0" + milliseconds;
      } else {
        return milliseconds;
      }
    }
  </script>
</body>
</html>


显示 时:分:秒.毫秒

<!DOCTYPE html>
<html>
<head>
  <title>秒表</title>
  <style>
    #second_watch {
      font-size: 24px;
      font-weight: bold;
      margin-bottom: 10px;
    }
  </style>
</head>
<body>
  <p id="second_watch">00:00:00.000</p>
  <p>
    <button id="time_start" onclick="startTimer()">开始</button>
    <button id="time_stop" onclick="stopTimer()">停止</button>
    <button id="time_reset" onclick="resetTimer()">重置</button>
  </p>

  <script>
    var timerInterval;
    var hours = 0;
    var minutes = 0;
    var seconds = 0;
    var milliseconds = 0;

    function updateTimer() {
      milliseconds += 10;
      if (milliseconds >= 1000) {
        milliseconds = 0;
        seconds++;
        if (seconds >= 60) {
          seconds = 0;
          minutes++;
          if (minutes >= 60) {
            minutes = 0;
            hours++;
          }
        }
      }

      var timeString = formatTime(hours) + ":" + formatTime(minutes) + ":" + formatTime(seconds) + "." + formatMilliseconds(milliseconds);
      document.getElementById("second_watch").textContent = timeString;
    }

    function startTimer() {
      document.getElementById("time_start").disabled = true;
      document.getElementById("time_stop").disabled = false;
      document.getElementById("time_reset").disabled = false;
      timerInterval = setInterval(updateTimer, 10);
    }

    function stopTimer() {
      document.getElementById("time_start").disabled = false;
      document.getElementById("time_stop").disabled = true;
      clearInterval(timerInterval);
    }

    function resetTimer() {
      document.getElementById("time_start").disabled = false;
      document.getElementById("time_stop").disabled = true;
      document.getElementById("time_reset").disabled = true;
      clearInterval(timerInterval);
      hours = 0;
      minutes = 0;
      seconds = 0;
      milliseconds = 0;
      document.getElementById("second_watch").textContent = "00:00:00.000";
    }

    function formatTime(time) {
      return time < 10 ? "0" + time : time;
    }

    function formatMilliseconds(milliseconds) {
      if (milliseconds < 10) {
        return "00" + milliseconds;
      } else if (milliseconds < 100) {
        return "0" + milliseconds;
      } else {
        return milliseconds;
      }
    }
  </script>
</body>
</html>