2012年10月19日星期五

js倒计时

js倒计时

Html:

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html "http://www.w3.org/1999/xhtml"> 3 <head runat="server"> 4     <title></title> 5     <script type="text/javascript" language="javascript"> 6         //获取剩余时间 7         function GetSurplusTime() { 8             var  9             if (window.ActiveXObject) {10                 new ActiveXObject("Microsoft.");11             } else if (window.12                 new 13             }14              function () {15                 if (4 && 200) {16                     SurplusTime.time_end = new Date(17                     CountdownTime();18                 }19             }20             "post", "GetTime.ashx", true);21             null);22         }23         var SurplusTime = {24             Time: {25                 Day: 0,26                 Hour: 0,27                 Minute: 0,28                 Second: 029             },30             Surplus: function () {31                 return SurplusTime.time_end.getTime() - SurplusTime.time_now().getTime();32             },33             ShowContent: function () {34                 var addtime = function (time) {35                     if (time < 10) time = "0" + time;36                     return "&nbsp;<span color='darkred'>" + time + "</span>";37                 }38                 var result = "今天距明天还有:";39                 result += addtime(SurplusTime.Time.Day) + "天";40                 result += addtime(SurplusTime.Time.Hour) + "时";41                 result += addtime(SurplusTime.Time.Minute) + "分";42                 result += addtime(SurplusTime.Time.Second) + "秒";43                 document.getElementById("show").innerHTML = result;44             },45             time_now: function () {46                 return new Date()47             },48             time_end: null,49             timerSurplus: null50         };51         function CountdownTime() {52             var surplus_time = SurplusTime.Surplus();53             if (surplus_time > 0) {54                 SurplusTime.Time.Day = Math.floor(surplus_time / 86400000)55                 surplus_time -= SurplusTime.Time.Day * 86400000;56                 SurplusTime.Time.Hour = Math.floor(surplus_time / 3600000)57                 surplus_time -= SurplusTime.Time.Hour * 3600000;58                 SurplusTime.Time.Minute = Math.floor(surplus_time / 60000)59                 surplus_time -= SurplusTime.Time.Minute * 60000;60                 SurplusTime.Time.Second = Math.floor(surplus_time / 1000);61                 SurplusTime.timerSurplus = setTimeout("CountdownTime()", 1000);62             }63             else if (SurplusTime.timerSurplus) clearTimeout(SurplusTime.timerSurplus);64             SurplusTime.ShowContent();65         }66         window.onload = GetSurplusTime;67     </script>68 </head>69 <body>70     <h3 align="center">71         奥运倒计时</h3>72     <form id="form1" runat="server">73     <div id="show">74     </div>75     </form>76 </body>77 </html>

Ashx处理:

1 public void ProcessRequest(HttpContext context)2         {3             context.Response.Write(DateTime.Now.AddDays(1).ToString());4         }

TAG: