zoukankan      html  css  js  c++  java
  • 发送验证码

    方法一:(setInterval)
    
    $("#getCode").on("click", getCodeClick);
    function getCodeClick() {
     $("#getCode").off("click");
     try {
        new common.ajaxRequest({
          url: url+"cmbntUser/getChangePhoneAuthCode?mobilePhone="+ $("#txtMobile").val().trim(),
          type: "POST",
          param: '',
          dataType: "json",
          header: header,
          callBack: function (result) {
            if(result.type =="SUCCESS"){
              var lefttime = 60;
              $("#getCode").attr("disabled", "disabled");
              $("#getCode").html("60秒后重新获取");
              var countDown = setInterval(function () {
                lefttime--;
                $("#getCode").html(lefttime + "秒后重新获取");
                 if (0 == lefttime) {
                   $("#getCode").html("重新获取");
                   $("#getCode").removeAttr("disabled");
                   $("#getCode").on("click", getCodeClick);
                  clearInterval(countDown);
                 }
              }, 1000);
             }else{
               $("#getCode").on("click", getCodeClick);
                   }
          }
       });
     }
      catch (ex) {
         $("#ErrMessage").html("发送短信失败,请稍后再试。");
        $("#ErrMessage").attr("class", "tip textred");
      }
      return false;
    }

    方法二:(setTimeout)

    function setTime(time){
        time --;
        $('#msgCodeBtn').attr('disabled',true).html(time+'秒后重新获取');
        var timeT = setTimeout(function(){
            setTime(time)
    },
    1000); if(time == 0){ $('#msgCodeBtn').removeAttr('disabled').html('重新获取'); clearTimeout(timeT); } } //发送验证码 $('#msgCodeBtn').on('click',function(){ var time = 60; $('#msgCodeBtn').html('60秒后重新获取'); setTime(time); });
  • 相关阅读:
    SQL Server 循环插入数据
    转:Visual Studio 打开程序提示仅我的代码怎么办
    DevExpress XAF 访问当前视图中选定的对象
    DevExpress安装
    待定位的小bug
    easyui datagrid的toolbar 按钮可以像linkbutton一样设置使能状态
    使用jquery同时设置两个对象的method为同一函数
    首页变黑白的办法
    关于jQueryEasyUI DateBox的基本使用
    好东西分享兼备忘
  • 原文地址:https://www.cnblogs.com/myyouzi/p/11162000.html
Copyright © 2011-2022 走看看