JS倒计时核心代码
废话不多,看代码
function wait() { if (_time <= 0) { document.location.reload(); return; } else { if (_time > 86400) { day = Math.floor(_time / 86400); hour = Math.floor((_time - day * 86400) / 3600); minute = Math.floor((_time - day * 86400 - hour * 3600) / 60); second = Math.floor(_time - day * 86400 - hour * 3600 - minute * 60); str = day + "天" + hour + "小时" + minute + "分" + second + "秒"; } else if (_time > 3600) { hour = Math.floor(_time / 3600); minute = Math.floor((_time - hour * 3600) / 60); second = Math.floor(_time - hour * 3600 - minute * 60); str = hour + "小时" + minute + "分" + second + "秒"; } else if (_time > 60) { minute = Math.floor(_time / 60); second = Math.floor(_time - minute * 60); str = minute + "分" + second + "秒"; } else { str = _time + "秒"; } $("#qrcode-exp").text(str); _time--; } setTimeout(function() { wait(); }, 1000) }