Simples de usar, mas não anti-atualização! !
<input type = "text" name = "code"> <classe de botão = "captchaBtn"> 码 短信 验证 码 </button>
<script>
$ ( function () {
$ ( ".captchaBtn"). on ("clique em ", function () {
// ...
contagem regressiva ( isto );
// ...
})
});
função contagem regressiva (obj) {
var that = $ (obj);
var segundos = 60 ;
that.attr ( "desativado", verdadeiro );
that.html (segundos + '秒' );= Novo novo Promise ((Resolve, Rejeitar) => {
let SetTimer = o setInterval (
() => {
segundos A - = 1. ;
// console.info ( 'Contagem regressiva:' segundos A +);
that.html (+ segundos A 'segunda' ) ;
if (seconds <= 0 ) {
that.html ( 'Get SMS Verification Code' );
resolve (setTimer)
}
}
, 1000 )
})
promessa.then ((setTimer) => {
// console.info ('清除');
clearInterval (setTimer);
that.attr ( "desativado", falso );
})
}
</script>