js验证码倒计时

原生JS

    countDown: function(){
        //倒计时
        var yzmBtns = document.getElementById("id");
        var waits=60;
        yzmBtns.setAttribute("disabled",true)
        yzmBtns.innerText=waits+'s';
        var timers = setInterval(() => {
          if(waits <= 1){
            waits=1;
            yzmBtns.innerText="重新验证";
            yzmBtns.removeAttribute("disabled")
            clearTimeout(timers)
          }else{
            waits--;
            yzmBtns.innerText=waits+'s';
          }
        }, 1000)
      }

 

posted @ 2018-02-10 11:55  web前端kelly  阅读(153)  评论(0编辑  收藏  举报