js倒計時

<div id="showtext">1</div>

<script type="text/javascript">
var $=function(id){return document.getElementById(id)}
var ltime=5
var y
function countDown(){
s=Math.floor(ltime/60)
//alert(s)
if(s>60){h=Math.floor(s/60);s=s%60;msg=h+"小時"+s+"分"

if(h>365){y=Math.floor(h/365);h=h%365;msg=y+"年"+h+"小時"+s+"分"}
}//msg=判斷輸出
else{msg=""}
m=ltime%60
$("showtext").innerHTML=msg+m+"秒"
--ltime

t=setTimeout("countDown()",1000)
if(ltime<0){clearTimeout(t);$("showtext").innerHTML="welcome our city!!"}
}
countDown();
</script>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章