倒數計時獲取驗證碼

火雲邪神發表於2018-07-11
<body>
    <input type="button" value="獲取驗證碼 60" style="margin:200px;border:1px #fd7722 solid;width:130px;height:45px;color:#fff;border-radius:4px;font-size:18px;outline:none;background:#4288f1;">
    <script>
      var npt = document.getElementsByTagName('input')[0];
      var nptnum = npt.addEventListener('click',function () {
          var num = 60;
         var  _this = this;
          var timer1 = window.setInterval(function (){  
              num -= 1;
              if (num < 60) _this.value = '已傳送 ' +  num;_this.disabled = true;
              if (num == 0) {
                  window.clearInterval(timer1); 
                  var timer2 = setTimeout(function () {
                _this.value = '點選重新獲取 ' + 60;_this.disabled = false;
              },2500);
            }
          },1000);
            // clearTimeout(timer2);
      },true)
    </script>
</body>

複製程式碼

相關文章