<p><span class="h" id="h"></span>时</p>
<p><span class="m" id="m"></span>分</p>
<p><span class="s" id="s"></span>秒</p>
<script type="text/javascript">
<!--
setInterval(
function(){
var date = new Date()
hours = date.getHours()
minutes = date.getMinutes()
seconds = date.getSeconds()
if(hours>=0 &&hours<10){
document.getElementById('tips').innerHTML = '距离抢购还剩下'
document.getElementById('h').innerHTML = (9-hours)
document.getElementById('m').innerHTML = seconds==0? (60-minutes) : (59-minutes)
document.getElementById('s').innerHTML = seconds==0? 0 : (60-seconds)
}else if(hours>=10 &&hours<20){
document.getElementById('tips').innerHTML = '抢购已持续'
document.getElementById('h').innerHTML = (hours-10)
document.getElementById('m').innerHTML = minutes
document.getElementById('s').innerHTML = seconds
}else{
document.getElementById('tips').innerHTML = '今日抢购已结束,感谢您的关注。'
document.getElementById('h').innerHTML = ''
document.getElementById('m').innerHTML = ''
document.getElementById('s').innerHTML = ''
}
},
1000)
-->
</script>
加判断呗。代码如下:LeaveDays=Math.floor(LeaveTime/(1000*60*60*24))//天
LeaveHours=Math.floor(LeaveTime/(1000*60*60)%24)//时
LeaveMinutes=Math.floor(LeaveTime/(1000*60)%60)//分
LeaveSeconds=Math.floor(LeaveTime/1000%60)//秒
if(parseInt(LeaveDays)<10){
LeaveDays="0"+LeaveDays
}
后面的几个和这个类似,你试试,希望可以帮到你.
JS实现倒计时(时、分,秒)var
interval
=
1000
function
ShowCountDown(year,month,day,divname)
{
var
now
=
new
Date()
var
endDate
=
new
Date(year,
month-1,
day)
var
leftTime=endDate.getTime()-now.getTime()
var
leftsecond
=
parseInt(leftTime/1000)
//var
day1=parseInt(leftsecond/(24*60*60*6))
var
day1=Math.floor(leftsecond/(60*60*24))
var
hour=Math.floor((leftsecond-day1*24*60*60)/3600)
var
minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60)
var
second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60)
var
cc
=
document.getElementById(divname)
cc.innerHTML
=
"脚本之家提示距离"+year+"年"+month+"月"+day+"日还有:"+day1+"天"+hour+"小时"+minute+"分"+second+"秒"
}
window.setInterval(function(){ShowCountDown(2010,4,20,'divdown1')},
interval)
[Ctrl+A
全选
注:如需引入外部Js需刷新才能执行]