Simple to use but not anti-refresh! !
<input type="text" name="code"><button class="captchaBtn">获取短信验证码</button>
<script>
$(function(){
$(".captchaBtn").on("click", function(){
//...
countdown(this);
//...
})
});
function countdown(obj){
var that = $(obj);
var seconds = 60;
that.attr("disabled", true);
that.html(seconds+'秒');
let promise = New new Promise ((Resolve, Reject) => {
the let setTimer = the setInterval (
() => {
seconds The - =. 1 ;
// console.info ( 'Countdown:' seconds The +);
that.html (+ seconds The 'second' ) ;
if (seconds <= 0 ) {
that.html ( 'Get SMS Verification Code' );
resolve (setTimer)
}
}
, 1000 )
})
promise.then ((setTimer) => {
// console.info('清除');
clearInterval(setTimer);
that.attr("disabled", false);
})
}
</script>