用js判斷60秒到計時,先定義一個變數refreshTime,當觸發事件的時候檢查一下上一次請求成功的時間距離現在是否超過60秒,如果沒有超過60秒,則彈出提示,
否則則允許繼續請求,請求成功之後,把當前的時間賦值給refreshTime,具體實現方式;
if(nowMinitePoint-Biz.AccountCenter.CellPhoneValidation.refreshTime
return false;
}
return true;
},
resetRefreshGet:function() //请求成功之后,调用的方法,把定义的变量重置为当前时间
{
var nowTime = new Date();
var nowMinitePoint=nowTime.getHours()*3600+nowTime.getMinutes()*60+nowTime.getSeconds();
Biz.AccountCenter.CellPhoneValidation.refreshTime=nowMinitePoint;
},
dynamicMessage:function(timeSecond) //倒计时方法 timeSecond为从多少秒开始,比如:60
{
var showTimmer;
if (showTimmer) {
clearTimeout(showTimmer);
}
if(timeSecond==dynamicValidate.refreshTimeLimit)
{
var messageRefresh =$.newegg.format(dynamicValidate.refreshSpanMessage,timeSecond);
$("#spanRefresh").html(""+messageRefresh+"");
$("#spanRefresh").attr("class","button btn_yanz_disable");
timeSecond--;
}
showTimmer = setTimeout(function () {
var messageRefresh =$.newegg.format(dynamicValidate.refreshSpanMessage,timeSecond);
$("#spanRefresh").html(""+messageRefresh+"");
timeSecond--;
if (timeSecond < 0) {
clearTimeout(showTimmer);
$("#spanRefresh").attr("class","button btn_yanz");
$("#spanRefresh").html(""+dynamicValidate.refreshMessage+"");
} else {
Biz.AccountCenter.CellPhoneValidation.dynamicMessage(timeSecond);
$("#spanRefresh").attr("class","button btn_yanz_disable");
}
}, 1000);
},
create: function(obj,page,isCancelPhone) //每次请求调用的方法
{
if(!Biz.AccountCenter.CellPhoneValidation.checkRefreshGet(dynamicValidate.refreshTimeLimit)) //每次请求的时候,js检查60s时间间隔
{
$("#valiateerror").empty().html(""+$.newegg.format($Resource.BuildContent("AccountCenter_ModifyDyanmic_CanNotRepeatClick"),dynamicValidate.refreshTimeLimit)+"").show();
$("#mobilewarning").hide();
return;
}
$.get("url",data,function(){
essage(dynamicValidate.refreshTimeLimit);//倒數計時
Biz .AccountCenter.CellPhoneValidation.resetRefreshGet();//重置時間
});