Remaining Time: 1 hour: 40 minutes: 30 seconds
Copy codeThe Code is as follows: 1 /*
* Countdown plug-in, mainly used for time-limited purchase
* By wayshan Version 1.0
* Usage:
* $ (Function (){
* $ ("# ElementId"). countdown ({
* Edate: "15:14:23"
*});
*})
*/
; (Function ($ ){
$. Fn. countdown = function (options ){
If (this. length = 0 ){
Return false;
}
Return this. each (function (){
Var Default = {
Sdate: null, // start time (Format: "10:10:10") can be set as the server time
Edate: null, // end date (Format: "10:10:10 ")
Callback: function (){
Return false;
}
},
_ H_Text = 'hour ',
_ M_Text = 'Min ',
_ S_Text = 'second ',
_ LT = null,
_ CT = new Date (),
_ ET = null,
_ ElT = null,
Ctime = null,
Etime = null,
DomId = null,
_ Timeout = null,
_ Gt = function (){
If (_ lT = null ){
_ ElT = (etime-ctime );
If (_ elT <0 ){
Certificate ('{'{domid}.html ("<strong> 0 </strong>" + _ H_Text + ": <strong> 0 </strong>" +
_ M_Text + ": <strong> 0 </strong>" + _ S_Text );
}
Var _ xT = Math. ceil (_ elT/(24*60*60*1000 ));
_ CT = parseInt (_ cT. match (/\ s (\ d +) \ D/) [1] * 3600)
+ ParseInt (_ cT. split (":") [1] * 60) + parseInt (_ cT. split (":") [2]);
_ ET = _ xT * 24*3600 + parseInt (_ eT. match (/\ s (\ d +) \ D/) [1] * 3600)
+ ParseInt (_ eT. split (":") [1] * 60) + parseInt (_ eT. split (":") [2]);
-LT = _ elT/1000;
}
If (_ elT> 0 ){
If (_ lT> = 0 ){
Var _ H = Math. floor (_ lT/3600 );
Var _ M = Math. floor (_ lT-_ H * 3600)/60 );
Var _ S = (_ lT-_ H * 3600) % 60;
Certificate ('{'{domid}.html ("<strong>" + _ H + "</strong>" + _ H_Text + ": <strong>"
+ _ M + "</strong>" + _ M_Text + ": <strong>" + _ S + "</strong>" + _ S_Text );
_ LT --;
} Else {
ClearInterval (_ timeout );
If (s. callback & $. isFunction (s. callback )){
S. callback. call (this );
}
}
} Else {
ClearInterval (_ timeout );
If (s. callback & $. isFunction (s. callback )){
S. callback. call (this );
}
}
},
StrDateTime = function (str ){
// Determine whether the input date and time is correct. The type must be in the format of 01:01:01
Var reg =/^ (\ d {}) (-| \/) (\ d {}) \ 2 (\ d }) (\ d {1, 2}) :( \ d {1, 2}) :( \ d {1, 2}) $ /;
Var r = str. match (reg );
If (r = null) return false;
Var d = new Date (r [1], r [3]-1, r [4], r [5], r [6], r [7]);
Return (d. getFullYear () = r [1] & (d. getMonth () + 1) = r [3] & d. getDate () = r [4]
& D. getHours () = r [5] & d. getMinutes () = r [6] & d. getSeconds () = r [7]);
}
Var s = $. extend ({}, Default, options || {});
DomId = this. id;
If (DomId = 'null '){
Return;
}
_ ET = s. Edate;
If (! StrDateTime (_ eT )){
Alert ('end Date Format incorrect ');
Return false;
}
If (s. Sdate! = Null ){
_ CT = s. Sdate;
}
_ CT = _ cT. toString ();
Cdate = _ cT. replace (/-/g ,'/');
_ ET = _ eT. toString ();
Edate = _ eT. replace (/-/g ,'/');
Ctime = new Date (cdate );
Etime = new Date (edate );
_ Timeout = setInterval (_ gt, 1000)
});
}
}) (JQuery );