JS Judge 60 seconds and Countdown sample code

Source: Internet
Author: User
Tags current time reset time interval

  This article is mainly on the JS 60 seconds and Countdown to the sample code is introduced, the need for friends can come to the reference, I hope to help you.

Use JS to judge 60 seconds to the time, first define a variable refreshtime, when the event is triggered to check the success of the last request is now more than 60 seconds, if not more than 60 seconds, pop-up prompts,   otherwise allow the request to continue, after the successful request, The current time assignment to refreshtime, the implementation of the way;     code is as follows: UsingNamespace ("Biz.accountcenter") ["Cellphonevalidation"]={       refreshtime:0,//variable       checkrefreshget:function (timelimit)/check time, TimeLimit the interval of time (in seconds) required for incoming requests, such as:     {      var nowtime = new Date ();       var n Owminitepoint=nowtime.gethours () *3600+nowtime.getminutes () *60+nowtime.getseconds ();        IF (Nowminitepoint-biz.accountcenter.cellphonevalidation.refreshtime<timelimit)      {         return false     &nbsp         &N Bsp;return true;    },       resetrefreshget:function ()//request succeeded, the method called to reset the defined variable to the current time     {  &NBSP ;    var nowtime = new Date ();        var Nowminitepoint=nowtime.gethouRS () *3600+nowtime.getminutes () *60+nowtime.getseconds ();        Biz.AccountCenter.CellPhoneValidation.refreshTime=nowMinitePoint;     }, & nbsp  dynamicmessage:function (Timesecond)//Countdown method Timesecond to start from how many seconds, such as:     {        var Showtimmer;        if (Showtimmer) {           cleartimeout (Showtimmer);   &NB Sp   &NBSP          if (timesecond==dynamicvalidate.refreshtimelimit)       & nbsp {            var Messagerefresh =$.newegg.format (Dynamicvalidate.refreshspanmessage, Timesecond);            $ ("#spanRefresh"). HTML ("<span>" +messagerefresh+ "</span>");             $ ("#spanRefresh"). attr ("Class", "button btn_yanz_disable");            timeSecond--;       &NBSP}          showtimmer = settimeout (function () {           var Messagerefresh =$.N Ewegg.format (Dynamicvalidate.refreshspanmessage,timesecond);            $ ("#spanRefresh"). HTML ("<span>" +messagerefresh+ "</span>");            timeSecond--;            if (Timesecond < 0) {               C Leartimeout (Showtimmer);                $ ("#spanRefresh") attr ("Class", "button Btn_yanz");                $ ("#spanRefresh"). HTML ("<span>" + Dynamicvalidate.refreshmessage+ "</span>");           &NBSP} else {               biz.accountcenter . Cellphonevalidation.dynamicmessage (Timesecond);                 $ ("#spanRefresh"). attr ("clAss "," button btn_yanz_disable ");           &NBSP,        }, 1000;    },       create:function (Obj,page,iscancelphone)//Per request Call method     {   &N Bsp         if (! Biz.AccountCenter.CellPhoneValidation.checkRefreshGet (Dynamicvalidate.refreshtimelimit))//per request, JS check 60s time interval         {           $ ("#valiateerror"). Empty (). HTML ("<span class= ' V Alidform_wrong ' > ' +$.newegg.format ($Resource. Buildcontent ("Accountcenter_modifydyanmic_ Cannotrepeatclick"), Dynamicvalidate.refreshtimelimit) + "</span>"). Show ();            $ ("#mobilewarning"). Hide ();            return;        }          $.get ("url", Data,function () {        & nbsp      //If successful              BIZ.ACcountCenter.CellPhoneValidation.dynamicMessage (dynamicvalidate.refreshtimelimit)/countdown              biz.accountcenter.cellphonevalidation.resetrefreshget ()/Reset time         });               }    

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.