點擊按鈕 倒計時60秒方可再次點擊發送的Js代碼

本節內容:
Javascript 實現 點擊按鈕 倒計時60秒方可再次點擊發送的效果。javascript

好比,一些網站上的手機短信認證的功能,有相似實現點擊按鈕後,倒計時60秒才能再次點擊發送的效果。html

本文用Javascript實現點擊按鈕後,倒計時60秒才能再次點擊發送驗證碼的功能。java

例子:網站

 

複製代碼代碼示例:this

<input type="button" id="btn" value="免費獲取驗證碼" />
<script type="text/javascript">
var wait=60;
function time(o) {
        if (wait == 0) {
            o.removeAttribute("disabled");            
            o.value="免費獲取驗證碼";
            wait = 60;
        } else { // www.jbxue.com
            o.setAttribute("disabled", true);
            o.value="從新發送(" + wait + ")";
            wait--;
            setTimeout(function() {
                time(o)
            },
            1000)
        }
    }
document.getElementById("btn").onclick=function(){time(this);}
</script>spa

相關文章
相關標籤/搜索