秒数显示:文本框
按钮(开始计时)按钮(停止计时)

解决方案 »

  1.   


    <script type="text/javascript">
    var tid;
    function timer(){
    var ret = document.getElementById('ret');
    if (tid) {
    clearInterval(tid);
    tid = null;
    } else {
    tid = setInterval(function(){
    ret.value = parseInt(ret.value) + 1;
    }, 100);
    }
    }
    </script>
    <input id="ret" type="text" value="0" readonly="true" />
    <input type="button" value="Start" onclick="timer()"/>
    <input type="button" value="Stop" onclick="timer()"/>
      

  2.   


    <script>
    var tid;
    function show(){
      var n = parseInt(document.forms[0].pad.value);
      document.forms[0].pad.value = n+1;
    }
    function doStart(){
      document.forms[0].pad.value="0";
      if(tid!=null){clearInterval(tid);tid=null;}
      tid=setInterval("show()",1000);
    }
    function doEnd(){
      
      if(tid!=null){clearInterval(tid);tid=null;}
    }</script><form>
    秒数显示 <input type="text" name="pad" value="0"><br>
    <input type="button" onclick="doStart();" value="开始计时">
    <input type="button" onclick="doEnd();" value="结束计时"></form>
      

  3.   

    <input id=s type=text value="0">
    <input type="button" id="start" onclick="startCount()" value="start" disabled/>
    <input type="button" id="stop" onclick="stopCount()" value="stop"/>
    <script>
    var flag = true;
    window.onload = function (){
    window.setInterval("count()",1000);
    };
    function startCount(){
    flag = true;
    document.getElementById("start").disabled = true;
    document.getElementById("stop").disabled = false;
    }
    function stopCount(){
    flag = false;
    document.getElementById("start").disabled = false;
    document.getElementById("stop").disabled = true;
    }
    function count(){
    if(flag){
    document.getElementById("s").value = parseInt(document.getElementById("s").value)+1;
    }
    }
    </script>
      

  4.   

      var s;
    var seconds=0;
    function StartTime() {
                 s=window.setInterval("StartCount()",1000);
             }
             function StartCount() {
                 seconds++;
                 document.getElementById("Text1").value = seconds;
             }
        function StopTime()
        {
              window.clearInterval(s);
        } <input id="Text1" type="text"  value=0 />秒
            <br />
            
            <input id="Button1" type="button" value="Start" onclick="StartTime()" />&nbsp;&nbsp;
    &nbsp; &nbsp;
            <input id="Button2" type="button" value="Stop" onclick="StopTime()" />