现在的位置: 首页 > 综合 > 正文

JS倒计时

2012年04月09日 ⁄ 综合 ⁄ 共 1010字 ⁄ 字号 评论关闭

<script language="JavaScript" type="text/javascript">
var now = new Date();
function createtime(){
var grt= new Date("8/08/2010 20:00:00");
now.setTime(now.getTime()+250);
days = (grt - now) / 1000 / 60 / 60 / 24;
dnum = Math.floor(days);
hours = (grt - now) / 1000 / 60 / 60 - (24 * dnum);
hnum = Math.floor(hours);
if(String(hnum).length ==1 ){hnum = "0" + hnum;}
minutes = (grt - now) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum);
mnum = Math.floor(minutes);
if(String(mnum).length ==1 ){mnum = "0" + mnum;}
seconds = (grt - now) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
snum = Math.round(seconds);
if(String(snum).length ==1 ){snum = "0" + snum;}

document.getElementById("timeDate").innerHTML = dnum +"天<br />"+ hnum + ":"+ mnum + ":"+ snum;
//document.getElementById("times").innerHTML = hnum + ":"+ mnum + ":"+ snum;
}
setInterval("createtime()",250);       
</script>

<style>
.Bjday{
    font-size: 20px;
    color: #009900;
    background-image: url(time.gif);
    background-repeat: no-repeat;
    height: 255px;
    width: 135px;
    padding-top: 150px;
    text-align: center;
    font-family: LCDMono;
}
</style>
<div class="Bjday" id="timeDate"></div>

【上篇】
【下篇】

抱歉!评论已关闭.