本意:循環執行3個函數,來改變ul節點的className,2秒后執行wait,3秒后執行stop,1秒后執行pass,依次循環。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