js判断60秒和倒计时示例代码
Using JS to judge 60 seconds to time, first define a variable refreshTime. 当触发事件时,检查最后一次请求的成功时间是否超过60秒,如果不超过60秒,则提示。否则,它被允许继续下去的请求,在请求是成功的,目前的时间分配到刷新时间,具体的实现方法;
复制代码代码如下所示:
UsingNamespace(。accountcenter ){cellphonevalidation} = {
刷新时间:0 /变量
checkrefreshget:功能(时限) / /时限为进料检验时间、请求的时间间隔(秒),如:60
{
VaR带=新的日期();
无功nowminitepoint = nowtime.gethours()* 3600 + nowtime.getminutes()* 60 + nowtime.getseconds();
如果(nowminitepoint圈。accountcenter。cellphonevalidation。刷新时间<时限)
{
返回false;
}
返回true;
},
(resetrefreshget: / /请求功能)的方法调用成功后,该变量的定义是重置为当前时间
{
VaR带=新的日期();
无功nowminitepoint = nowtime.gethours()* 3600 + nowtime.getminutes()* 60 + nowtime.getseconds();
biz。accountcenter。cellphonevalidation。刷新时间= nowminitepoint;
},
dynamicmessage:功能(timesecond) /倒计时的方法timesecond从秒数开始,例如:60
{
无功showtimmer;
如果(showtimmer){
ClearTimeout(showtimmer);
}
如果(timesecond = = dynamicvalidate。refreshtimelimit)
{
无功messagerefresh =美元。newegg.format(dynamicvalidate.refreshspanmessage,timesecond);
$(# spanrefresh)。Html(+ messagerefresh + );
$(# spanrefresh)。Attr(班
timesecond --;
}
showtimmer = setTimeout(){()函数(
无功messagerefresh =美元。newegg.format(dynamicvalidate.refreshspanmessage,timesecond);
$(# spanrefresh)。Html(+ messagerefresh + );
timesecond --;
如果(timesecond<0){
ClearTimeout(showtimmer);
$(# spanrefresh)。Attr(班
$(# spanrefresh)。Html(+ dynamicvalidate。refreshmessage + );
{人}
biz.accountcenter.cellphonevalidation.dynamicmessage(timesecond);
$(# spanrefresh)。Attr(班
}
},1000);
},
创建:功能(obj,网页,iscancelphone) / /方法要求每个请求
{
如果(!biz.accountcenter.cellphonevalidation.checkrefreshget(dynamicvalidate。refreshtimelimit)) / /每一次请求,检查JS 60s时间间隔
{
$(# valiateerror ),空()。Html(+ $。新蛋。格式($ resource.buildcontent (accountcenter_modifydyanmic_cannotrepeatclick ),dynamicvalidate。refreshtimelimit)+()表示();
$(# mobilewarning )藏();
返回;
}
获取(url
如果成功
biz.accountcenter.cellphonevalidation.dynamicmessage(dynamicvalidate。refreshtimelimit); / /倒计时
(商务。accountcenter。cellphonevalidation。resetrefreshget); / /复位时间
});
}
}