Get verification code var countdown = 60;var but = document.getElementById("/> Get verification code var countdown = 60;var but = document.getElementById(">

Home >Backend Development >PHP Tutorial >Javascript Get verification code 60 seconds countdown

Javascript Get verification code 60 seconds countdown

一个新手
一个新手Original
2017-10-17 09:47:452363browse

<button id="time">获取验证码</button>
var countdown = 60;
var but = document.getElementById(&#39;time&#39;);
but.addEventListener(&#39;click&#39;, function (e) {
    setTime(this);
})

function setTime (elem) {
    if (countdown === 0) {
        elem.innerHTML = "获取验证码";
        countdown = 5;
        elem.disabled = false;
        clearTimeout(anima);
    } else {
        countdown--;
        elem.innerHTML = "重新获取(" + countdown + ")";        
        elem.disabled = true;
        var anima = setTimeout(function () {
            setTime(elem);
        }, 1000);
    }
}

The above is the detailed content of Javascript Get verification code 60 seconds countdown. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn