Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<script src= "Http://img.jb51.net/jslib/jquery/jquery-1.7.1.min.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >
function ShowTime (Tuanid, time_distance) {
This.tuanid = Tuanid;
PHP time is seconds, JS time is microseconds
this.time_distance = time_distance * 1000;
}
ShowTime.prototype.setTimeShow = function () {
var timer = $ ("#lefttime_" + This.tuanid);
var str_time;
var int_day, Int_hour, Int_minute, Int_second;
Time_distance = this.time_distance;
This.time_distance = this.time_distance-1000;
if (Time_distance > 0) {
Int_day = Math.floor (time_distance/86400000);
Time_distance-= Int_day * 86400000;
Int_hour = Math.floor (time_distance/3600000);
Time_distance-= Int_hour * 3600000;
Int_minute = Math.floor (time_distance/60000);
Time_distance-= Int_minute * 60000;
Int_second = Math.floor (time_distance/1000);
if (Int_hour < 10)
Int_hour = "0" + int_hour;
if (Int_minute < 10)
Int_minute = "0" + int_minute;
if (Int_second < 10)
Int_second = "0" + int_second;
Str_time = Int_day + "Days" + Int_hour + "hours" + int_minute + "Minutes" + Int_second + "seconds";
Timer.text (Str_time);
var self = this;
settimeout (function () {self.settimeshow ();}, 1000); D: Correct
} else {
Timer.text ("End of group purchase");
Return
}
}
</script>
<body>
<div id= "Lefttime_1" time= "2011/11/23 6:58:23" >
</div>
<script type= "Text/javascript" >
var st = new ShowTime (1,3);
St.tuanid = 1;
St.time_distance = 10000;
St.settimeshow ();
</script>
<div id= "lefttime_2" time= "2011/11/24 6:58:23" >
</div>
<script type= "Text/javascript" >
var st = new ShowTime (2, 5);
St.tuanid = 1;
St.time_distance = 10000;
St.settimeshow ();
</script>
</body>
The above code needs to use jquery, you can notice