Rumah >pembangunan bahagian belakang >tutorial php >Javascript 获取验证码60秒倒计时
<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); } }
Atas ialah kandungan terperinci Javascript 获取验证码60秒倒计时. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!