发送验证码设置settime(验证码倒计时)

function settime ($el,countdown) {
  if(countdown === 0){
    $el.removeAttr('disabled')
    // $el.val('发送验证码').css('backgroundColor','#e70034')
    $el.val('获取验证码').css('backgroundColor','transparent')
  }else{
    // $el.attr('disabled', 'true').css('backgroundColor','#bfbfbf')
    $el.attr('disabled', 'true').css('backgroundColor','transparent')
    $el.val(`重新发送(${countdown}s)`)
    countdown--
    setTimeout(function() {
      settime($el,countdown)
    }, 1000);
  }
}
原文地址:https://www.cnblogs.com/queende7/p/8669003.html