jquery implementation of the judgment countdown whether the end code

Source: Internet
Author: User

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

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.