<script type="text/javascript" src="js/jquery-1.12.1.js"></script>
<script type="text/javascript" >
var ti2;
$(function(){
arr=[1,2,3,4,5];
var n = arr.length;
$("div").html("倒计时:"+n);
var ti=setInterval(function(){
n--;
$("div").html("倒计时:"+n);
if(n==0){
clearInterval(ti);
timing();
$("#ok").click(sub);
return;
}
},1000)
});
function timing(){
var m = 3;
ti2=setInterval(function(){
$("div").html("倒计时:"+m);
m--;
if(m<0){
alert("fail");
clearInterval(ti2);
return;
}
},1000);
}
function sub(){
clearInterval(ti2);
timing();
}
</script>
原文:http://www.cnblogs.com/animagi/p/5282125.html