有bug,誰幫我看下
這是我的js代碼,不知為何點擊按鈕可以執行一次,接著就執行不了了,還有就是點擊按鈕,然后為什么倒計時會延遲一會才開始計時的?球解答
function play(){
?? ??? ??? var send = document.getElementById('send');
?? ??? ??? timer = null;
?? ??? ??? times = 60;
?? ??? ?
?? ??? ? send.onclick = function(){
?? ??? ??? ? alert('已下發短信到您的手機,請注意查收');
?? ??? ??? ? timer = setInterval(function(){
?? ??? ??? ??? ? if(times<=0){
?? ??? ??? ??? ??? ?send.value = "發送驗證碼";
?? ??? ??? ??? ??? ?send.removeAttribute('disabled');
?? ??? ??? ??? ??? ?clearInterval('timer');
?? ??? ??? ??? ? }else{
?? ??? ??? ??? ??? ?times--;
?? ??? ??? ??? ??? ?send.value = times +'秒后重試';
?? ??? ??? ??? ??? ?send.disabled = true;
?? ??? ??? ??? ? }?? ?
?? ??? ??? ? },1000)
?? ??? ? }
?? ?}
2016-06-18
?clearInterval('timer');中timer的單引號去掉就可以了
2016-04-16
不需要設置disable就可以實現
你可以最開始設置
flag=0;
? timer = setInterval(function(){
if(flag==0){
flag=1;
?? if(times<=0){
?? ??? ??? ??? ??? ?send.value = "發送驗證碼";
????????????????????clearInterval('timer');
???????????????????? flag=0;
???????????????? }else{
?? ??? ??? ??? ??? ?times--;
?? ??? ??? ??? ??? ?send.value = times +'秒后重試';?
???????????????????
???????????????? }????
}
??????????????
???????????? },1000)
2016-04-10
試著???clearInterval('timer'); ?上邊加一個 times=60;就可以了