The notation of JS and JQ Countdown

Source: Internet
Author: User

The page needs to make a countdown function, and then the Niang again, find two ways of writing, the original JS and JQ, after testing the native JS in IE may not refresh the phenomenon so combined with a great god of the JQ wording modified one.

Native JS notation:

Html:

<Divclass= "Time">  <spanID= "T_d"></span>  <spanID= "T_h"></span>  <spanID= "T_m"></span>  <spanID= "t_s"></span></Div>

Js:

<script>functionGetrtime () {varEndtime=NewDate (' 2015/06/19 22:00:00 ')); varNowtime =NewDate (); varT =endtime.gettime ()-Nowtime.gettime (); varD=math.floor (t/1000/60/60/24); varH=math.floor (t/1000/60/60%24);varM=math.floor (t/1000/60%60); varS=math.floor (T/1000%60);document.getElementById ("T_d"). InnerHTML =D + "Day"; document.getElementById ("T_h"). InnerHTML =H + "when"; document.getElementById ("T_m"). InnerHTML =m + "min"; document.getElementById ("t_s"). InnerHTML =s + "seconds"; } setinterval (Getrtime,0);</script>

This kind of writing, JS part is easy to read.

Combined with JQ modified version:

The HTML section is the same as above, mainly the JS section:

<script type= "Text/javascript" >varEndtime=NewDate (' 2015/06/19 22:00:00 '));varNowtime =NewDate ();varT =endtime.gettime ()-nowtime.gettime ();varIntdiff = parseint (t/1000);//Countdown total number of seconds, because it is in milliseconds, so divided by 1000 is the secondfunctionTimer (Intdiff) {Window.setinterval (function(){    varDay=0, hour=0, Minute=0, Second= 0;//Time Default Value    if(Intdiff > 0) { Day= Math.floor (Intdiff/(60 * 60 * 24)); Hour= Math.floor (Intdiff/())-(Day * 24); Minute= Math.floor (INTDIFF/60)-(Day *)-(Hour * 60); Second= Math.floor (Intdiff)-(Day *)-(Hour *)-(MINUTE * 60); }    if(Hour <= 9) hour = ' 0 ' +hour; if(minute <= 9) minute = ' 0 ' +minute; if(Second <= 9) Second = ' 0 ' +second; $(' #t_d '). html (day+ "days")); $(' #t_h '). html (hour+ ' time '); $(' #t_m '). html (minute+ ' points ')); $(' #t_s '). HTML (second+ ' s ')); Intdiff--; }, 1000);} $(function() {timer (intdiff);});</script>

The notation of JS and JQ Countdown

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.