时间: 2020-09-9|13次围观|0 条评论

<!-- dom --><input id="send" type="button" value="发送验证码">
// 原生js版本var times = 60, // 临时设为60秒    timer = null;document.getElementById('send').onclick = function () {    // 计时开始    timer = setInterval(function () {        times--;        if (times <= 0) {            send.value = '发送验证码';            clearInterval(timer);            send.disabled = false;            times = 60;        } else {            send.value = times + '秒后重试';            send.disabled = true;        }    }, 1000);}
// jQuery版本var times = 60,    timer = null;$('#send').on('click', function () {    var $this = $(this);    // 计时开始    timer = setInterval(function () {        times--;        if (times <= 0) {            $this.val('发送验证码');            clearInterval(timer);            $this.attr('disabled', false);            times = 60;        } else {            $this.val(times + '秒后重试');            $this.attr('disabled', true);        }    }, 1000);});

文章转载于:https://www.jianshu.com/p/896e4d9a3891

原著是一个有趣的人,若有侵权,请通知删除

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《验证码倒计时代码
   

还没有人抢沙发呢~