js判断60秒以及倒计时示例代码_javascript技巧
否则则允许继续请求,请求成功之后,把当前的时间赋值给refreshTime,具体实现方式;
usingNamespace("Biz.AccountCenter")["CellPhoneValidation"]={
refreshTime:0, //变量
checkRefreshGet:function(timeLimit) //检查时间,timelimit为传入请求需要间隔的时间(单位秒),比如: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() //请求成功之后,调用的方法,把定义的变量重置为当前时间
{
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 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(){
//如果成功
Biz.AccountCenter.CellPhoneValidation.dynamicMessage(dynamicValidate.refreshTimeLimit);//倒计时
Biz.AccountCenter.CellPhoneValidation.resetRefreshGet();//重置时间
});
}
}
推荐阅读
-
JS判断浏览器类型与版本的实现代码_javascript技巧
-
js实现局部页面打印预览原理及示例代码_javascript技巧
-
JS 屏蔽按键效果与改变按键效果的示例代码_javascript技巧
-
判断文件是否正在被使用的JS代码_javascript技巧
-
js或者jquery判断图片是否加载完成实现代码_javascript技巧
-
js 判断checkbox是否选中的实现代码_javascript技巧
-
JS判断网页广告是否被浏览器拦截过滤的代码_javascript技巧
-
利用js实现前台动态添加文本框,后台获取文本框内容(示例代码)_javascript技巧
-
js判断60秒以及倒计时示例代码_javascript技巧
-
js实现点小图看大图效果的思路及示例代码_javascript技巧