问答详情
源自:8-3 计时器setInterval()

计时器的显示

怎么让计时器按照时:分:秒显示,没有闪烁

提问者:ailing20 2016-07-28 09:10

个回答

  • qq_深渊_1
    2016-08-05 13:44:06

    var attime;
      function clock(){
        var time=new Date();         
        var hour=aa(time.getHours());
        var minute=aa(time.getMinutes());
        var second=aa(time.getSeconds());
        attime=hour+":"+minute+":"+second;
        document.getElementById("clock").value = attime;
      }
      function aa(x){
          if(x<10)
          {
              return "0"+x;
          }else{
              return x;
          }
      }
      setInterval(clock,100);

  • 慕粉3724156
    2016-07-28 09:54:15

    window.onload = function(){
    var HH = 0;
    var mm = 0;
    var ss = 0;
    var str = '';
    var timer = setInterval(function(){
    str = "";

    if(++ss==60)
    {
    if(++mm==60)
    {
    HH++;
    mm=0;
    }
    ss=0;
    }

    str+=HH<10?"0"+HH:HH;
    str+=":";
    str+=mm<10?"0"+mm:mm;
    str+=":";
    str+=ss<10?"0"+ss:ss;
    document.getElementById("d").innerHTML = str;
    },1000);
    };

  • 光与暗_0
    2016-07-28 09:45:11

       var i;

       function sj()

      {

         var js=new Date();

        document.getElementById("xs").value=js.getHours()+"时"+js.getMinutes()+"分"+js.getSeconds()+"秒";

     

      }setInterval("sj()",1000);

    定义了一个input,id为"xs"