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

Javascript Get verification code 60 seconds countdown

一个新手
Release: 2023-03-16 16:54:02
Original
2332 people have browsed it

<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);
    }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template