Answers
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>倒计时</title>
</head>
<body>
<center id="time"></center>
<script type="text/javascript">
var deadline = new Date(2015,9,7,19,22,34)//截止时间,注意月的下从0开始,所以这个是10月的倒计时
var time //记录剩余时间,以毫秒计
window.onload = function(){
setInterval(function(){
var curTime = new Date().getTime()
var time = deadline.getTime()-curTime //算出剩余毫秒数
var remainTime = parseInt(time/1000) //剩余时间,以秒计
var day = parseInt( remainTime/(24*3600) )//剩余天
var hour = parseInt( (remainTime-day*24*3600)/3600 )//剩余小时
var minute = parseInt((remainTime-day*24*3600-hour*3600)/60)//剩余分钟
var sec = parseInt(remainTime%60)//剩余秒
document.getElementById('time').textContent=day+"天"+hour+"时"+minute+"分"+sec+"秒"
},50);
}
</script>
</body>
</html>
madbxm
answered 9 years, 5 months ago