计时器
第一种:根据页面时间倒计时
(function(){
var startCountDown = function(){
var hours = parseInt($("#J_hour").text())
var minutes = parseInt($("#J_minute").text())
var seconds = parseInt($("#J_second").text())
if (seconds <= 0) {
if (minutes <= 0) {
if (hours <= 0) {
alert("时间结束!")
return
} else {
hours--
}
minutes = 59
} else {
minutes--
}
seconds = 59
} else {
seconds--
}
$("#J_second").html((seconds).toString().length > 1 ? seconds : "0" + seconds)
$("#J_minute").html((minutes).toString().length > 1 ? minutes : "0" + minutes)
$("#J_hour").html((hours).toString().length > 1 ? hours : "0" + hours)
time = setTimeout(startCountDown, 1000)
}
window.startCountDown = startCountDown
})()
第二种:js指定时间倒计时
(function(){
var seconds = 60
var startCountDown = function(){
if (seconds <= 0) {
console.log("获取超时!")
} else {
console.log("请耐心等待(" + (seconds--) + "s)")
}
time = setTimeout(startCountDown, 1000)
}
window.startCountDown = startCountDown
})()