放學(xué)了倒計(jì)時(shí)
<script type="text/javascript">
function task(){
var now=new Date();
var end=new Date('2018/5/25 18:00');
var s=(end-now)/1000;
if(s>0){
var h=Math.floor(s/3600);
var m=Math.floor(s%3600/60);
s=Math.floor(s%60);
document.querySelector('span').innerHTML=h+'小時(shí)'+m+'分鐘'+s+'秒';
}else{
clearInterval(timer);
document.querySelector('span').innerHTML='放學(xué)了';
}
}
task();
var timer=setInterval(task,1000);
function stop(btn){
if(btn.innerHTML=="||"){
clearInterval(timer)
btn.innerHTML="|>";
}else{
timer=setInterval(task,1000);
btn.innerHTML="||";
}
}
</script>
。