应用场景:点名倒计时/抽奖/距离活动结束
倒计时.PNG一个函数即可解决
function countDown(mi = 0, ss = 0) {
let end = setInterval(() => {
var txt =
(mi < 10 ? "0" + mi : mi) + "'" + (ss < 10 ? "0" + ss : ss) + "''";
span.innerHTML = txt;
ss--;
if (ss == -1 && mi > 0) {
ss = 59;
mi--;
countDown(mi, ss);
}
if (mi == 0&&ss==-1) {
clearTimeout(end);
return;
}
}, 1000);
}
调用 参数为 (分钟,秒数)
countDown(1, 10);
网友评论