js实现60s倒计时效果
适用于获取验证码等其他场景,下面代码直接粘贴句可以使用
// 60s获取验证码的js与html var timer = null; var count = 60; $('.box>button').click(function() { var codeText = $('.code').text(); if (codeText == '获取验证码') { timer = setInterval(function(){ count--; $('.code').text(count+'后获取验证码'); if (count <=0) { clearInterval(timer); $('.code').text('获取验证码'); } },1000); } }); html: <!-- 60s倒计时 --> <div class='box'> <button class='code'>获取验证码</button> </div>