Javascript 实现 点击按钮 倒计时60秒方可再次点击发送的效果
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <a href="javascript:void(0);" id="gSMS" onclick="get_sms_captcha('2')">获取短信验证码</a> </body> </html>
Javascript代码:
var countDownT = 60; function get_sms_captcha(type){ countDownT = 60; setTime(); //下方写业务 } function setTime(){ if (countDownT == 0){ $("#gSMS").attr("onclick","get_sms_captcha('2')"); $("#gSMS").text("获取短信验证码"); } else{ $("#gSMS").attr("onclick","#"); $("#gSMS").text("重新发送("+countDownT+")"); countDownT--; setTimeout(function () { setTime(); },1000) } }
效果图:
文章评论(0)