<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>倒计时</title>
<script type="text/javascript">
window.onload=setTime;
function setTime(){
var setTime = document.getElementById("setTime");
var d = new Date();
var now = d.getTime();
var end = Date.parse("2019-11-11");
var totalSeconds = end-now;
var day = Math.floor(totalSeconds/1000/60/60/24);
var hours = Math.floor(totalSeconds/1000/60/60%24);
var minutes = Math.floor(totalSeconds/1000/60%60);
var seconds = Math.floor(totalSeconds/1000%60);
setTime.innerHTML = day +"天"+minutes +"分钟"+seconds+"秒";
setTimeout("setTime()",1000);
if(totalSeconds<0){
clearTimeout();
document.getElementById("box").innerHTML = "倒计时结束";
}
}
</script>
</head>
<body>
<p id="box">倒计时:<br/>距离2019年11月11日<br/>还有<span id="setTime"></span></p>
</body>
</html>