- <!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>
- </head>
-
- <body>
- <div id="time"></div>
- <script src="time.js"></script>
- <script>
- var test = new Countdown("time","2012/1/30,12:20:12");
- test.SetTime();
- </script>
- </body>
- </html>
-
-
-
-
-
-
- function Countdown(elem,endTime){
- this.elem = elem;
- this.nowTime = new Date().getTime();
- this.endTime = new Date(endTime).getTime();
- this.getID = document.getElementById(this.elem);
- this.reg = /\s+/g;
- }
- Countdown.prototype = {
- SetTime : function(){
- var that = this;
- t = setInterval(function(){
- that.DownTime();
- },1000)
- },
- zero : function(n){
- var n = parseInt(n,10);
- if(n>0){
- if(n<10){
- n = "0" +n;
- }
- return String(n);
- }else{
- return "00";
- }
- },
- DownTime : function(){
- var space = parseInt((this.endTime - this.nowTime)/1000);
- this.nowTime+=1000;
- var d,h,m,s;
- var isboolean = true;
- if(space<=0){
- isboolean = false;
- }
- if(isboolean == true){
- d = this.zero(parseInt(space/3600/24)) + "天";
- h = this.zero(parseInt((space/3600)%24)) + "时";
- m = this.zero(parseInt((space/60)%60)) + "分";
- s = this.zero(parseInt(space%60)) + "秒";
- }else{
- d = 0 + "天";
- h = 0 + "时";
- m = 0 + "分";
- s = 0 + "秒";
- }
- total = d + h + m + s;
- this.getID.innerHTML = total.replace(this.reg,"");
- }
-
- }
|