自己定义了个时间函数;获得当前系统时间,时分秒。再用一个按钮事件来开始、暂停时间;该如何做。
详细说明,注释

解决方案 »

  1.   

    var flag=true;
    function changeFlag(){
      var but1=document.getElementById("but1");
      if(flag){
       flag=false;
       but1.value="开始";
      }else{
       flag=true;
       but1.value="停止";
      }
    }
    setInterval(function(){
       if(flag){
    ...执行时间刷新
       }
    },1000);<input id="but1" type="button" onlick="changeFlag();"  value="停止"/>
      

  2.   

    clearTimeout(t1)  t1为setTimeout()返回的值
      

  3.   

    setTimeout  设置时间就行
      

  4.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title> new document </title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style>
    .clockwrap td{font-size:32px; font-family:Arial;text-align:center;color:#333}
    .clockwrap td#clock_sec{font-size:12px; padding:10px 0 0 2px;font-weight:normal}
    .clockwrap td#maohao{width:26px;overflow:hidden;font-size:24px;}
    </style>
    </head>
    <body>
    <div id="clockwrap" class="clockwrap"><table><tbody><tr><td>00</td><td id="maohao">:</td><td>00</td><td id="clock_sec">00</td></tr></tbody></table></div>
    <input type="button" value="stop" onclick="fPas();" /><input type="button" value="start" onclick="fGo()" />
    <script type="text/javascript">
    var clock = {
    timer: null,
    showTime: function(hour1, hour2, min1, min2, sec1, sec2) {
       document.getElementById('clockwrap').innerHTML = '<table><tr><td>' +
    hour1 + hour2 +
    '</td><td id="maohao">:' +
    '</td><td>' +
    min1 + min2 +
    '</td><td id="clock_sec">' +
    sec1 + sec2 +
    '</td></tr></table>';
    },
    start: function() {
    this.timer = setInterval(function() {
    var now = new Date(),
    h = ('0' + now.getHours()).slice(-2),
    m1 = Math.floor(now.getMinutes() / 10),
    m2 = now.getMinutes() % 10,
    s1 = Math.floor(now.getSeconds() / 10),
    s2 = now.getSeconds() % 10;
    clock.showTime(h.charAt(0),h.charAt(1), m1, m2, s1, s2);
    }, 1000);
    },
    stop: function() {
    window.clearInterval(this.timer);
    }
    };
    clock.start();
    function fPas() { clock.stop(); }
    function fGo() { clock.start(); }
    </script>
    </body>
    </html>