This article mainly introduces the sample code for js judgment 60 seconds and countdown. You can refer to the Code for help.
Use js to determine the 60-second timing. First, define a variable refreshTime. When an event is triggered, check whether the last request was successful for more than 60 seconds. If not, A prompt is displayed. Otherwise, the request is allowed. After the request is successful, the current time is assigned to refreshTime. The implementation method is as follows: usingNamespace ("Biz. accountCenter ") [" CellPhoneValidation "] = {refreshTime: 0, // variable checkRefreshGet: function (timeLimit) // check time, timelimit is the interval (in seconds) required for incoming requests, for example: 60 {var nowTime = new Date (); var nowMinitePoint = nowTime. getHours () * 3600 + nowTime. getMinutes () * 60 + nowTime. getSeco Nds (); if (nowMinitePoint-Biz.AccountCenter.CellPhoneValidation.refreshTime <timeLimit) {return false;} return true;}, resetRefreshGet: function () // method called after successful request, reset the defined variable to the current time {var nowTime = new Date (); var nowMinitePoint = nowTime. getHours () * 3600 + nowTime. getMinutes () * 60 + nowTime. getSeconds (); Biz. accountCenter. cellPhoneValidation. refreshTime = nowMinitePoint;}, dynamicMessage: function (timeSecond )/ /The Countdown method timeSecond starts from the second, for example: 60 {var showTimmer; if (showTimmer) {clearTimeout (showTimmer);} if (timeSecond = dynamicValidate. refreshTimeLimit) {var messageRefresh = $. newegg. format (dynamicValidate. refreshSpanMessage, timeSecond); $ ("# spanRefresh" ).html ("<span>" + messageRefresh + "</span>"); $ ("# spanRefresh "). attr ("class", "button btn_yanz_disable"); timeSecond --;} showTimmer = setTimeout (function () {Var messageRefresh = $. newegg. format (dynamicValidate. refreshSpanMessage, timeSecond); $ ("# spanRefresh" ).html ("<span>" + messageRefresh + "</span>"); timeSecond --; if (timeSecond <0) {clearTimeout (showTimmer); $ ("# spanRefresh "). attr ("class", "button btn_yanz"); $ ("# spanRefresh" ).html ("<span>" + dynamicValidate. refreshMessage + "</span>");} else {Biz. accountCenter. cellPhoneValidation. dynamicMessage (timeS Econd); $ ("# spanRefresh "). attr ("class", "button btn_yanz_disable") ;},1000) ;}, create: function (obj, page, isCancelPhone) // The method {if (! Biz. accountCenter. cellPhoneValidation. checkRefreshGet (dynamicValidate. refreshTimeLimit) // js checks the 60 s interval at each request {$ ("# valiateerror" ..empty().html ("<span class = 'validform _ wrong '>" + $. newegg. format ($ Resource. buildContent ("AccountCenter_ModifyDyanmic_CanNotRepeatClick"), dynamicValidate. refreshTimeLimit) + "</span> "). show (); $ ("# mobilewarning "). hide (); return;} $. get ("url", data, function () {// If Biz is successful. accountCenter. cellPhoneValidation. dynamicMessage (dynamicValidate. refreshTimeLimit); // countdown to Biz. accountCenter. cellPhoneValidation. resetRefreshGet (); // reset time });}}