JS实现网站倒计时

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript"> 
<!--
    var target = []
    var time_id = []
    function show_date_time_0() {
        setTimeout("show_date_time_0()", 1000);
        for (var i = 0, j = target.length; i < j; i++) {
            today = new Date();
            timeold = target[i] - today.getTime();
            sectimeold = timeold / 1000;
            secondsold = Math.floor(sectimeold);
            msPerDay = 24 * 60 * 60 * 1000;
            e_daysold = timeold / msPerDay;
            daysold = Math.floor(e_daysold);
            e_hrsold = (e_daysold - daysold) * 24;
            hrsold = Math.floor(e_hrsold);
            e_minsold = (e_hrsold - hrsold) * 60;
            minsold = Math.floor((e_hrsold - hrsold) * 60);
            seconds = Math.floor((e_minsold - minsold) * 60);
            if (daysold < 0) {
                document.getElementById(time_id[i]).innerHTML = "逾期,倒计时已经失效";
            }
            else {
                if (hrsold < 10) { hrsold = "0" + hrsold }
                if (minsold < 10) { minsold = "0" + minsold }
                if (seconds < 10) { seconds = "0" + seconds }
                if (daysold < 3) {
                    document.getElementById(time_id[i]).innerHTML = "<font color=red>" + daysold + "天" + hrsold + "小时" + minsold + "分" + seconds + "秒</font>";
                }
                else {
                    document.getElementById(time_id[i]).innerHTML = daysold + "天" + hrsold + "小时" + minsold + "分" + seconds + "秒";
                }
            }
        }
    }
    setTimeout("show_date_time_0()", 100); 
//--> 
</script>
</head>
<body>
 
距离2012年元旦节: 
<div id="TimeCounter_0" style="border:1px solid black;margin:5px;padding:2px;width:140px"></div> 
<script type="text/javascript">
    //设定目标时间(数组元素) 
    //target[target.length]=new Date(年,月-1,日,时,分,秒).getTime() 
    target[target.length] = new Date(2012, 12, 01, 00, 00, 00).getTime();
    //设定倒计时显示地址(数组元素) 
    time_id[time_id.length] = "TimeCounter_0" 
</script> 
 
距2012小光棍节(1.11): 
<div id="TimeCounter_1" style="border:1px solid black;margin:5px;padding:2px;width:140px"></div> 
<SCRIPT>
    target[target.length] = new Date(2012, 0, 11, 00, 00, 00).getTime()
    time_id[time_id.length] = "TimeCounter_1" 
</SCRIPT> 
 
距2012春节(2.2): 
<div id="TimeCounter_3" style="border:1px solid black;margin:5px;padding:2px;width:140px"></div> 
<SCRIPT>
    target[target.length] = new Date(2012, 1, 2, 00, 00, 00).getTime()
    time_id[time_id.length] = "TimeCounter_3" 
</SCRIPT> 
</body>
</html>
    </form>
</body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值