JavaScript 倒计时函数
作者:
k_zone | 来源:发表于
2019-10-14 14:32 被阅读0次let countTime = 24*60*60*1000 // 一天的时间戳
let time2text = function (t) {
var s = String(100 + Math.floor(t / 1000) % 60).slice(1)
var m = String(100 + Math.floor(t / 60000) % 60).slice(1)
var h = String(100 + Math.floor(t / 3600000)).slice(1)
console.log(h + ':' + m + ':' + s)
return h + ':' + m + ':' + s
}
let countDown = function () {
console.log(countTime)
time2text(countTime)
if (countTime >= 1000) {
setTimeout(()=>{
countTime--
countDown()
}, 1000)
} else {
console.log('倒计时结束')
}
}
countDown()
本文标题:JavaScript 倒计时函数
本文链接:https://www.haomeiwen.com/subject/zmfryctx.html
网友评论