溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

js如何實現(xiàn)簡單的獲取驗證碼按鈕效果

發(fā)布時間:2021-06-18 14:57:58 來源:億速云 閱讀:261 作者:小新 欄目:web開發(fā)

小編給大家分享一下js如何實現(xiàn)簡單的獲取驗證碼按鈕效果,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

效果圖:

js如何實現(xiàn)簡單的獲取驗證碼按鈕效果

圖(1)初始圖

js如何實現(xiàn)簡單的獲取驗證碼按鈕效果

圖(2)點擊后

代碼如下:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>pro.html</title>
<style type="text/css">
.checkCode {
  cursor: pointer;
  border: 1px solid black;
  text-align: center;
  line-height: 26px;
  width: 115px;
  height: 35px;
}
</style>
<script type="text/javascript">
  var sleep = 30, interval = null;
  window.onload = function ()
  {
    var btn = document.getElementById ('btn');
    btn.onclick = function ()
    {
      if (!interval)
      {
        this.style.backgroundColor = 'rgb(243, 182, 182)';
        this.disabled = "disabled";
        this.style.cursor = "wait";
        this.value = "重新發(fā)送 (" + sleep-- + ")";
        interval = setInterval (function ()
        {
          if (sleep == 0)
          {
            if (!!interval)
            {
              clearInterval (interval);
              interval = null;
              sleep = 30;
              btn.style.cursor = "pointer";
              btn.removeAttribute ('disabled');
              btn.value = "免費獲取驗證碼";
              btn.style.backgroundColor = '';
            }
            return false;
          }
          btn.value = "重新發(fā)送 (" + sleep-- + ")";
        }, 1000);
      }
    }
  }
</script>
</head>
<body>
  <input class="checkCode" type="button" id="btn" value="免費獲取驗證碼" />
</body>
</html>

看完了這篇文章,相信你對“js如何實現(xiàn)簡單的獲取驗證碼按鈕效果”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

js
AI