js获取验证码倒计时

<button type="button" id='getting' onclick="time(this)" class="mui-btn text-primary" style="height: 40px;30%;">获取验证码</button>

 //倒计时
 var wait = 60;
 function time(btnObj) {
     if(wait == 0) {
         btnObj.removeAttribute("disabled");
         btnObj.textContent = "重新发送";
         wait = 60;
     } else {
         btnObj.setAttribute("disabled", true);
         btnObj.textContent = wait + "";
         wait--;
         setTimeout(function() {
             time(btnObj)
         }, 1000)
     }
 }
原文地址:https://www.cnblogs.com/yydxh/p/15133125.html