本意:循環(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],哪里有問題?
JS對象賦值無效?
尚方寶劍之說
2018-10-20 10:14:41