課程
/前端開發(fā)
/JavaScript
/Tab選項(xiàng)卡切換效果
for(times=60;times>0;times--){send.value=times+"秒后重新發(fā)送";}
2017-03-19
源自:Tab選項(xiàng)卡切換效果 3-4
正在回答
window.onload=function(){
? ?var send=document.getElementById('send'),
? ? ? ?times=60,
? ? ? ?timer=null;
? ?send.onclick=function(){
? ? ?// 計(jì)時開始?
? ? ? ? ?this.disabled="disabled"; ?
? ? ? ?timer=setInterval(function(){
? ? ? ? ? ? ?times--;?
? ? ? ? ? ? ?send.value=times+"秒后重試";
? ? ? ? ? ? ?if(times==0){
? ? ? ? ? ? ? send.disabled=false
? ? ? ? ? ? ? ? ?clearInterval(timer);
? ? ? ? ? ? ? ? ?send.value="請發(fā)送驗(yàn)證碼";
? ? ? ? ? ? ? ? ?times=60
? ? ? ? ? ? ?} ??
? ? ? ? ? ??
? ? ? ? },1000)
? ?
? ?}?
}
setInterval 第二個參數(shù)是毫秒, 要設(shè)置成1000,不是100.
你這沒定時器,電腦運(yùn)行你這循環(huán)代碼,幾乎是秒完成,你壓根看不到變化。當(dāng)然直接跳到最后
不好意思,修改一下。
倒數(shù)第二次循環(huán)~~當(dāng)times=2時;times>0; ? 輸出:2秒后重新發(fā)送 ?; times-- ?
最后一次循環(huán)~~~times=1;times>0; ?輸出:1秒后重新發(fā)送 ?; ? times--?
? ? ? ? ? ? ? ? ? ?times=0;不滿足條件 退出循環(huán),。。。所以最后輸出為1.
因?yàn)?
最后一次循環(huán)~~~times=1;times>0; ?輸出:2秒后重新發(fā)送 ?; ? times--?
我覺得應(yīng)該是因?yàn)閟end.value會直接顯示最后的值,不會隨著for循環(huán)改變value,你可以用一個定時器對send的value值進(jìn)行改變,我在你的代碼下面加了一個consol.log(times+"秒后重新發(fā)送");是可以在控制臺輸出60~1的語句的。
var?send=document.getElementsByClassName('send')[0]; ????????var?times=60; ????????setInterval(time,100) ????????function?time(){ ????????????times--; ????????????send.value=times+'秒后重新發(fā)送'; ????????????(times<=0)&&(send.value='重新發(fā)送'); ????????}
舉報(bào)
本課程詳細(xì)介紹網(wǎng)頁頁面中最流行常用的tab切換效果
3 回答為什么不能直接寫,要再寫一個for循環(huán)
3 回答for循環(huán)的使用
1 回答for循環(huán)問題
1 回答為什么我的for循環(huán)不起作用
1 回答for循環(huán)給標(biāo)簽添加id
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2018-11-30
window.onload=function(){
? ?var send=document.getElementById('send'),
? ? ? ?times=60,
? ? ? ?timer=null;
? ?send.onclick=function(){
? ? ?// 計(jì)時開始?
? ? ? ? ?this.disabled="disabled"; ?
? ? ? ?timer=setInterval(function(){
? ? ? ? ? ? ?times--;?
? ? ? ? ? ? ?send.value=times+"秒后重試";
? ? ? ? ? ? ?if(times==0){
? ? ? ? ? ? ? send.disabled=false
? ? ? ? ? ? ? ? ?clearInterval(timer);
? ? ? ? ? ? ? ? ?send.value="請發(fā)送驗(yàn)證碼";
? ? ? ? ? ? ? ? ?times=60
? ? ? ? ? ? ?} ??
? ? ? ? ? ??
? ? ? ? },1000)
? ?
? ?}?
}
2018-10-16
setInterval 第二個參數(shù)是毫秒, 要設(shè)置成1000,不是100.
2017-05-08
你這沒定時器,電腦運(yùn)行你這循環(huán)代碼,幾乎是秒完成,你壓根看不到變化。當(dāng)然直接跳到最后
2017-05-06
不好意思,修改一下。
倒數(shù)第二次循環(huán)~~當(dāng)times=2時;times>0; ? 輸出:2秒后重新發(fā)送 ?; times-- ?
最后一次循環(huán)~~~times=1;times>0; ?輸出:1秒后重新發(fā)送 ?; ? times--?
? ? ? ? ? ? ? ? ? ?times=0;不滿足條件 退出循環(huán),。。。所以最后輸出為1.
2017-05-06
因?yàn)?
倒數(shù)第二次循環(huán)~~當(dāng)times=2時;times>0; ? 輸出:2秒后重新發(fā)送 ?; times-- ?
最后一次循環(huán)~~~times=1;times>0; ?輸出:2秒后重新發(fā)送 ?; ? times--?
? ? ? ? ? ? ? ? ? ?times=0;不滿足條件 退出循環(huán),。。。所以最后輸出為1.
2017-03-20
我覺得應(yīng)該是因?yàn)閟end.value會直接顯示最后的值,不會隨著for循環(huán)改變value,你可以用一個定時器對send的value值進(jìn)行改變,我在你的代碼下面加了一個consol.log(times+"秒后重新發(fā)送");是可以在控制臺輸出60~1的語句的。