jQuery 实现验证码倒计时
jQuery 版本==jquery-1.9.1.min.js
实现代码如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="jquery-1.9.1.min.js"></script> <script type="text/javascript"> let countdown=60; $("#btn").click(function () { let obj = $(this); settime(obj); }); function settime(obj) { //发送验证码倒计时 if (countdown === 0) { obj.attr('disabled',false); //obj.removeattr("disabled"); obj.text("免费获取验证码"); countdown = 60; return; } else { obj.attr('disabled',true); obj.text("重新发送(" + countdown + ")"); countdown--; } setTimeout(function() { settime(obj) } ,1000) } </script> <body> <input type="button" id="btn" value="免费获取验证码" /> </body> </html>