jquery implementation of the judgment countdown whether the end code:
This section describes a code example, this code can determine whether the current date has been the end of the countdown, this code does not have a countdown effect, just to determine whether the countdown is complete, such as shopping site discount period, although the actual application, there will be few similar code, but hope to bring some inspiration to the visitors.
The code is as follows:
function done () { var str=$ (' #end '). Text (); var out=str.match (/\d+/g); Console.log (out); var h=parseint (out[0]), M=parseint (Out[1]), S=parseint (out[2]); Console.log (H + ' # ' +m+ ' # ' +s); var calc=h*3600+m*60+s; Console.log (calc); if (calc==0) { //code } else{ console.log (' Waiting for. '); } var t=settimeout (' Done () ', 1000);} Done ();
The above is just the code snippet, not able to demonstrate, the following describes its implementation process.
A. Code Comment:
1.function done () {}, this function realizes the countdown end effect.
2.var str=$ (' #end '). Text () to get the textual content of the specified element, the current time in this code should be countdown.
3.var Out=str.match (/\d+/g), gets an array of numbers in the time date.
4.var H=parseint (out[0]), M=parseint (Out[1]), S=parseint (out[2]), get hours, minutes, and seconds, respectively.
5.var Calc=h*3600+m*60+s, converted into seconds.
6.if (calc==0) {//code}, determine whether the countdown is over, and then specify the appropriate action.
7.var t=settimeout (' Done () ', 1000), performs a judgment function every second.
8.done (), execute this function.
Two. Related reading:
The 1.match () function can refer to the regular expression match () function section.
The 2.setTimeout () function can be found in the setTimeout () Function usage section.
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=14641
For more information, refer to: http://www.softwhy.com/jquery/
jquery implementation of the judgment countdown whether the end code