国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

js判斷60秒以及倒計時示例代碼

2024-05-06 15:59:48
字體:
來源:轉載
供稿:網友
本篇文章主要是對js判斷60秒以及倒計時的示例代碼進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助

用js判斷60秒到計時,首先定義一個變量refreshTime,當觸發事件的時候檢查一下上一次請求成功的時間距離現在是否超過60秒,如果沒有超過60秒,則彈出提示,

否則則允許繼續請求,請求成功之后,把當前的時間賦值給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<timeLimit )
     {
         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("<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) //每次請求調用的方法
    {    
        if(!Biz.AccountCenter.CellPhoneValidation.checkRefreshGet(dynamicValidate.refreshTimeLimit)) //每次請求的時候,js檢查60s時間間隔
        {
           $("#valiateerror").empty().html("<span>"+$.newegg.format($Resource.BuildContent("AccountCenter_ModifyDyanmic_CanNotRepeatClick"),dynamicValidate.refreshTimeLimit)+"</span>").show();
           $("#mobilewarning").hide();
           return;
        }

       $.get("url",data,function(){

             //如果成功
             Biz.AccountCenter.CellPhoneValidation.dynamicMessage(dynamicValidate.refreshTimeLimit);//倒計時
             Biz.AccountCenter.CellPhoneValidation.resetRefreshGet();//重置時間
       });
       
    }
 }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 宣威市| 吴川市| 互助| 库车县| 桐城市| 蕉岭县| 荣成市| 芷江| 靖江市| 武穴市| 惠东县| 高唐县| 镶黄旗| 寿阳县| 浪卡子县| 晋城| 吴川市| 康马县| 大田县| 图片| 长兴县| 佛学| 鹿泉市| 利川市| 美姑县| 和硕县| 宝兴县| 馆陶县| 三河市| 孙吴县| 磐安县| 湄潭县| 鄱阳县| 大关县| 九江县| 弋阳县| 齐河县| 秭归县| 伊宁县| 大悟县| 武清区|