js 定时器

 

//定时器间隔0.5s,启动定时器后,等待3s

refreshCount=function() {
      var time = 500;
      var interval; //调度器对象。
      function fun(){
        console.log("获取进度");
      }
      interval = setInterval(fun,time);//去掉引号就对了
      return interval
    }

x=refreshCount();
setTimeout(function(){clearInterval(x);console.log("结束定时器!");}, 3000);

输出

"获取进度"
"获取进度"
"获取进度"
"获取进度"
"获取进度"
"获取进度"
结束定时器!

 

posted @ 2019-04-24 23:36  anobscureretreat  阅读(202)  评论(0编辑  收藏  举报