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