js判斷60秒以及倒計(jì)時(shí)示例代碼
用js判斷60秒到計(jì)時(shí),首先定義一個(gè)變量refreshTime,當(dāng)觸發(fā)事件的時(shí)候檢查一下上一次請(qǐng)求成功的時(shí)間距離現(xiàn)在是否超過(guò)60秒,如果沒(méi)有超過(guò)60秒,則彈出提示,
否則則允許繼續(xù)請(qǐng)求,請(qǐng)求成功之后,把當(dāng)前的時(shí)間賦值給refreshTime,具體實(shí)現(xiàn)方式;
usingNamespace("Biz.AccountCenter")["CellPhoneValidation"]={
refreshTime:0, //變量
checkRefreshGet:function(timeLimit) //檢查時(shí)間,timelimit為傳入請(qǐng)求需要間隔的時(shí)間(單位秒),比如: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() //請(qǐng)求成功之后,調(diào)用的方法,把定義的變量重置為當(dāng)前時(shí)間
{
var nowTime = new Date();
var nowMinitePoint=nowTime.getHours()*3600+nowTime.getMinutes()*60+nowTime.getSeconds();
Biz.AccountCenter.CellPhoneValidation.refreshTime=nowMinitePoint;
},
dynamicMessage:function(timeSecond) //倒計(jì)時(shí)方法 timeSecond為從多少秒開(kāi)始,比如: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) //每次請(qǐng)求調(diào)用的方法
{
if(!Biz.AccountCenter.CellPhoneValidation.checkRefreshGet(dynamicValidate.refreshTimeLimit)) //每次請(qǐng)求的時(shí)候,js檢查60s時(shí)間間隔
{
$("#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(){
//如果成功
Biz.AccountCenter.CellPhoneValidation.dynamicMessage(dynamicValidate.refreshTimeLimit);//倒計(jì)時(shí)
Biz.AccountCenter.CellPhoneValidation.resetRefreshGet();//重置時(shí)間
});
}
}
- 微信小程序?qū)崿F(xiàn)倒計(jì)時(shí)60s獲取驗(yàn)證碼
- 微信小程序動(dòng)態(tài)顯示項(xiàng)目倒計(jì)時(shí)效果
- 微信小程序電商常用倒計(jì)時(shí)實(shí)現(xiàn)實(shí)例
- Android中微信小程序支付倒計(jì)時(shí)功能
- 微信小程序 倒計(jì)時(shí)組件實(shí)現(xiàn)代碼
- AngularJS 驗(yàn)證碼60秒倒計(jì)時(shí)功能的實(shí)現(xiàn)
- 點(diǎn)擊按鈕出現(xiàn)60秒倒計(jì)時(shí)的簡(jiǎn)單js代碼(推薦)
- js代碼實(shí)現(xiàn)點(diǎn)擊按鈕出現(xiàn)60秒倒計(jì)時(shí)
- 微信小程序注冊(cè)60s倒計(jì)時(shí)功能 使用JS實(shí)現(xiàn)注冊(cè)60s倒計(jì)時(shí)功能
相關(guān)文章
JS組件Bootstrap實(shí)現(xiàn)圖片輪播效果
這篇文章主要為大家詳細(xì)介紹了JS組件Bootstrap實(shí)現(xiàn)圖片輪播效果的具體代碼,對(duì)圖片輪播效果感興趣的小伙伴們可以參考一下2016-05-05JavaScript 檢測(cè)瀏覽器和操作系統(tǒng)的腳本
代碼轉(zhuǎn)自《Professional JavaScript™ for Web Developers》一書(shū)。2008-12-12微信小程序MUI導(dǎo)航欄透明漸變功能示例(通過(guò)改變r(jià)gba的a值實(shí)現(xiàn))
這篇文章主要介紹了微信小程序MUI導(dǎo)航欄透明漸變功能,結(jié)合實(shí)例形式分析了通過(guò)改變r(jià)gba的a值實(shí)現(xiàn)透明度漸變功能的相關(guān)操作技巧,需要的朋友可以參考下2019-01-01js性能優(yōu)化之?dāng)?shù)組模式實(shí)例詳解
這篇文章主要為大家介紹了js性能優(yōu)化之?dāng)?shù)組模式實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10詳解Webpack + ES6 最新環(huán)境搭建與配置
這篇文章主要介紹了詳解Webpack + ES6 最新環(huán)境搭建與配置,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-06-06javascript StringBuilder類(lèi)實(shí)現(xiàn)
一個(gè)簡(jiǎn)單的StringBuilder類(lèi)實(shí)現(xiàn)2008-12-12