美文网首页
倒计时 发送验证码

倒计时 发送验证码

作者: Rose_yang | 来源:发表于2020-12-16 14:59 被阅读0次
    // 倒计时
    export function TimerEnd (elm, iNum) {
      this.init(elm, iNum)
    }
    TimerEnd.prototype = {
      init: function (obj, iNum) {
        setTimeout(() => {
          this.oSecond = document.getElementById(obj)
          removeClass(this.oSecond, 'btn-red')
          this.oSecond.innerText = '60秒后重发'
          this.timer = null
          this.iSecond = 60
          if (!this.oSecond) return
          this.interval(iNum)
        }, 0)
        return this
      },
      interval: function (iNum) {
        var isec = iNum || this.iSecond
        addClass(this.oSecond, 'disabled')
        this.timer = setInterval(() => {
          this.oSecond.innerText =
            isec <= 10 ? '0' + --isec + '秒后重发' : --isec + '秒后重发'
          if (isec <= 0) {
            clearInterval(this.timer)
            removeClass(this.oSecond, 'disabled')
            addClass(this.oSecond, 'btn-red')
            this.oSecond.innerText = '重新获取'
          }
        }, 1000)
      },
      clearTimer: function () {
        this.timer && clearInterval(this.timer)
      }
    }
    

    相关文章

      网友评论

          本文标题:倒计时 发送验证码

          本文链接:https://www.haomeiwen.com/subject/zudboctx.html