欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

Javascript 获取验证码60秒倒计时

程序员文章站 2022-05-05 17:24:53
...
<button id="time">获取验证码</button>
var countdown = 60;
var but = document.getElementById('time');
but.addEventListener('click', 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);
    }
}

以上就是Javascript 获取验证码60秒倒计时的详细内容,更多请关注其它相关文章!