JS Judge 60 seconds and Countdown sample code _javascript Tips

Source: Internet
Author: User
Tags time interval

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, the request is allowed to continue, after the success of the request, the current time assigned to Refreshtime, the specific way to achieve;

Copy Code code as follows:

UsingNamespace ("Biz.accountcenter") ["Cellphonevalidation"]={
refreshtime:0,//variable

Checkrefreshget:function (timelimit)/check time, timelimit the time required for incoming requests (in seconds), for example: 60
{
var nowtime = new Date ();
var nowminitepoint=nowtime.gethours () *3600+nowtime.getminutes () *60+nowtime.getseconds ();

if (nowminitepoint-biz.accountcenter.cellphonevalidation.refreshtime<timelimit)
{
return false;
}
return true;
},

Resetrefreshget:function ()///After the request succeeds, the method called 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 to start from how many seconds, such as: 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 (Timesecond);
$ ("#spanRefresh"). attr ("Class", "button btn_yanz_disable");
}
}, 1000);
},

Create:function (Obj,page,iscancelphone)//Per request invocation method
{
if (! Biz.AccountCenter.CellPhoneValidation.checkRefreshGet (Dynamicvalidate.refreshtimelimit))//per request, JS check 60s time interval
{
$ ("#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 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.