Js 60 s judgment and countdown example code _ javascript skills

Source: Internet
Author: User
This article mainly introduces the sample code for js judgment of 60 seconds and countdown. If you need a friend, you can refer to it and hope to help you determine the 60 seconds to the timer using js, first, define a variable refreshTime. When an event is triggered, check whether the previous request was successful for more than 60 seconds. If not, a prompt is displayed,

Otherwise, the request is allowed to continue. After the request is successful, the current time is assigned to refreshTime. The specific implementation method is as follows;

The Code 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. getSeconds ();

If (nowMinitePoint-Biz.AccountCenter.CellPhoneValidation.refreshTime {
Return false;
}
Return true;
},

ResetRefreshGet: function () // after the request is successful, call the method to 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) // countdown method timeSecond is from how many seconds, for example: 60
{
Var showTimmer;
If (showTimmer ){
ClearTimeout (showTimmer );
}

If (timeSecond = dynamicValidate. refreshTimeLimit)
{
Var messageRefresh = $. newegg. format (dynamicValidate. refreshSpanMessage, timeSecond );
$ ("# SpanRefresh" pai.html ("" + messageRefresh + "");
$ ("# SpanRefresh"). attr ("class", "button btn_yanz_disable ");
TimeSecond --;
}

ShowTimmer = setTimeout (function (){
Var messageRefresh = $. newegg. format (dynamicValidate. refreshSpanMessage, timeSecond );
$ ("# SpanRefresh" pai.html ("" + messageRefresh + "");
TimeSecond --;
If (timeSecond <0 ){
ClearTimeout (showTimmer );
$ ("# SpanRefresh"). attr ("class", "button btn_yanz ");
$ ("# SpanRefresh" pai.html ("" + dynamicValidate. refreshMessage + "");
} Else {
Biz. AccountCenter. CellPhoneValidation. dynamicMessage (timeSecond );
$ ("# SpanRefresh"). attr ("class", "button btn_yanz_disable ");
}
},1000 );
},

Create: function (obj, page, isCancelPhone) // method of each request call
{
If (! Biz. AccountCenter. CellPhoneValidation. checkRefreshGet (dynamicValidate. refreshTimeLimit) // js checks the 60 s interval for each request
{
$ ("# Valiateerror" ).empty().html ("" + $. newegg. format ($ Resource. BuildContent ("updated"), dynamicValidate. refreshTimeLimit) + ""). show ();
$ ("# Mobilewarning"). hide ();
Return;
}

$. Get ("url", data, function (){

// If successful
Biz. AccountCenter. CellPhoneValidation. dynamicMessage (dynamicValidate. refreshTimeLimit); // countdown
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.