如何在一个页面使多个setInterval函数正常运行

var firstInterval;
var secondInterval;

function firstAlert(){
  if(firstInterval) clearInterval(firstInterval);
<span style="white-space:pre">	</span>//处理所有
<span style="white-space:pre">	</span>.........
<span style="white-space:pre">	</span>firstInterval = setInterval('firstAlert()', 1000*2);
}


function secondAlert(){
  if(secondInterval) clearInterval(secondInterval);
<span style="white-space:pre">	</span>//处理所有
<span style="white-space:pre">	</span>.......


secondInterval = setInterval('secondAlert()', 1000*3);
  }




代码是贴别人的,原理就是声明全局变量用来承载定时器,并且在页面入口处
if(xxx) clearInterval(xxx);清除已存在的定时器,避免出现混乱
原文地址:https://www.cnblogs.com/nmgxl-home/p/5742615.html