html部分
<h2>倒计时:(国庆节)</h2>
<span id="down"></span><br>
<button onclick="start()">start</button>
<button onclick="end()">stop</button><br>
js部分~~~~~~
<script>
//距离2017年还有
function start(){
str=setInterval("lick()",1000);
}
function lick()
{
var time=new Date();
var miao=time.getTime();
var times=new Date("Oct 1,2017 12:00:00");
var miao2=times.getTime();
var cutt=miao2-miao;
var sec=Math.ceil(cutt/1000%60);
var min=Math.ceil(cutt/1000/60%60);
var hour=Math.ceil(cutt/1000/60/60%24);
var day=Math.ceil(cutt/1000/60/60/24);
document.getElementById("down").innerHTML=day+"天"+hour+"小时"+min+"分"+sec+"秒";
document.getElementById("down").style.color="red";
}
function end(){
clearInterval(str);
}
<script>