用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;
    },

&nbsp;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);
    },

   &nbsp;create: function(obj,page,isCancelPhone) //每次请求调用的方法
&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!Biz.AccountCenter.CellPhoneValidation.checkRefreshGet(dynamicValidate.refreshTimeLimit)) //每次请求的时候,js检查60s时间间隔
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $("#valiateerror").empty().html("<span class='Validform_wrong'>"+$.newegg.format($Resource.BuildContent("AccountCenter_ModifyDyanmic_CanNotRepeatClick"),dynamicValidate.refreshTimeLimit)+"</span>").show();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $("#mobilewarning").hide();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }

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

             //如果成功
             Biz.AccountCenter.CellPhoneValidation.dynamicMessage(dynamicValidate.refreshTimeLimit);//倒计时
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Biz.AccountCenter.CellPhoneValidation.resetRefreshGet();//重置时间
       });
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    }
&nbsp;}

标签:
60秒倒计时

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com

评论“js判断60秒以及倒计时示例代码”

暂无“js判断60秒以及倒计时示例代码”评论...

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。