JS 驗證碼60秒倒計時
阿新 • • 發佈:2019-01-27
<script>
var $yzm = document.getElementById('yzmBtn'),
flag = false;
$yzm.onclick = function(){
var time=60;
var h;
if(flag){
return false;
}
flag = true;
h= setInterval(function(){
$yzm.style.backgroundColor='#eee' ;
$yzm.style.border='1px solid #ccc';
$yzm.style.color='#777';
$yzm.style.cursor='not-allowed';
if(time<10){
time='0'+time;
}
$yzm.value=time+'秒後重新獲取';
time--;
if(time<0){
clearInterval(h);
flag = false ;
$yzm.value='獲取驗證碼';
$yzm.style.backgroundColor='#4DB749';
$yzm.style.border='none';
$yzm.style.color='#fff';
$yzm.style.cursor='pointer';
}
},1000);
}
</script>