第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JS對象賦值無效?

JS對象賦值無效?

尚方寶劍之說 2018-10-20 10:14:41
本意:循環(huán)執(zhí)行3個函數(shù),來改變ul節(jié)點的className,2秒后執(zhí)行wait,3秒后執(zhí)行stop,1秒后執(zhí)行pass,依次循環(huán)。HTML部分 <ul id="traffic" class="wait">     <li><span></span></li>      <li><span></span></li>      <li><span></span></li>   </ul>JS部分var statusList=[      {        func:function(){          traffic.className='wait';        },        timer:2000      },      {        func:function(){          traffic.className='stop';        },        timer:3000      },      {        func:function(){          traffic.className='pass';        },        timer:1000      }      ];          var currentIndex = 0;    var statusObj=statusList[currentIndex];    setInterval(        function(){            statusObj.func();            debugger;            currentIndex=(currentIndex+1)%statusList.length;            console.log(currentIndex);        },        statusObj.timer    );即使右邊的statusList[currentIndex]在改變,statusObj變量一直是statusList[0],哪里有問題?
查看完整描述

1 回答

?
波斯汪

TA貢獻1811條經(jīng)驗 獲得超4個贊

哥們,你只更新了下標序號,沒有更新statusObj對象啊,它只被賦值了一次,就是數(shù)組內(nèi)的第一個元素啊,你可以將

 function(){
                statusObj.func();                debugger;
                currentIndex=(currentIndex+1)%statusList.length;                console.log(currentIndex);
            }

改成

function(){
                statusObj.func();                debugger;
                currentIndex=(currentIndex+1)%statusList.length;
                statusObj = statusList[currentIndex];                console.log(currentIndex);
            }


查看完整回答
反對 回復 2018-11-08
  • 1 回答
  • 0 關注
  • 1004 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號