码迷,mamicode.com
首页 > Web开发 > 详细

JS,JQ实现暂停FOR循环,间隔几秒后再继续执行

时间:2017-06-21 11:46:08      阅读:3461      评论:0      收藏:0      [点我收藏+]

标签:--   on()   timer   lib   type   alert   input   put   margin   

<!DOCTYPE html>
<head>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
</script>
<script>
function testing(){
  var string = ‘1u2,1u3,1u4,1u5‘;
     var count = 0;
     for (var i = 0; i < string.length; i++) {
         if (string[i] == ‘,‘) {
             count++;
              }
         }
 mytimer = setInterval(function(){test();}, 2000);  //利用setInterval实现间隔两秒执行一次test()函数
 function test(){
  var barcode=string.split(‘,‘)[count];
  count--;
  if(count<0){clearInterval(mytimer);}  //clearInterval取消循环
  alert(barcode);
  
 }
}
</script>
</head>
<body>
<input type="button" style="margin-left:50%;margin-top:20%;"  value="test" onclick="testing();" />
</body>
</html>

JS,JQ实现暂停FOR循环,间隔几秒后再继续执行

标签:--   on()   timer   lib   type   alert   input   put   margin   

原文地址:http://www.cnblogs.com/llmm/p/7058183.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!