Js judgment 60 seconds and countdown sample code

Source: Internet
Author: User

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 });}}

Related Article

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.