使い方は簡単ですが、リフレッシュしないでください!!
<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 SETTIMER = のsetInterval(
() => {
秒 - = 1。;
// console.info( 'カウントダウン'秒+);
that.html(+秒'第2' );
if(seconds <= 0 ){
that.html( 'Get SMS Verification Code' );
resolve(setTimer)
}
}
、 1000 )
})
promise.then((setTimer) => {
// console.info( '清除');
clearInterval(setTimer);
that.attr( "disabled"、false );
})
}
</ script>