The same page multiple merchandise countdown JS based on object-oriented javascript_ time and date

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.