闭包递归
软谋教育
跳转5
$(function() {
var num = $("#count-down span b").text();
var timer;
countDown(num);
$(".jump").click(function() {
jump();
})
//判断倒计时
function countDown(n) {
if(n>0){
setTimeout(function(){
n--;
$("#count-down span b").text(n);
countDown(n);
},1000)
}else {
jump();
}
};
function jump() {
$("#count-down").fadeOut(800);
if(timer){
clearInterval(timer);
}
timer = setInterval(setClock,1000);
}
//记录上网时长
var h=0,m=0,s=0,str="";
function setClock() {
str="";
if(++s == 60){
if(++m== 60){
h++;
m=0;
}
s=0;
}
/*if(s<10){
str+='0'+s;
}else {
str+=s;
};*/
str += h<10?'0'+h:h;
str += ":";
str += m<10?'0'+m:m;
str += ":";
str += s<10?'0'+s:s;
$("#ptime").text(str);
}
})