html:
<input type="button" class="validCode" value="获取验证码" />
js:
var validCode=true;
$(".validCode").click (function () {
var time=60;
var $code=$(this);
if (validCode) {
validCode=false;
console.log(‘验证码已发出‘);
var t=setInterval(function () {
time--;
$code.val(time+"秒");
if (time==0) {
clearInterval(t);
$code.val("重新获取");
validCode=true;
}
},1000)
}
})
原文:https://www.cnblogs.com/zhaoshuxin/p/14113624.html