纯JavaScript,动态显示倒计时,粘到notepad就能用
<div>
Registration closes in <span id="timer">02:00<span> minutes!
</div>
<script>
window.onload = function(){
var hour = 1;
var sec = 59;
var refreshId = setInterval(function(){
document.getElementById("timer").innerHTML = hour +" : " + sec ;
sec--;
if(sec==0){
if(hour>0){
hour--;
sec=59;
}else{
clearInterval(refreshId);
setTimeout(function() {
document.getElementById("timer").innerHTML = 0 +" : " + 0 ;
}, 1000);
}
}
},1000);
}
</script>