<head><meta charset="UTF-8"><title></title><script> window.onload = function(){ var imgArr=["img/1.jpg","img/2.jpg","img/3.jpg","img/4.jpg","img/5.jpg","img/6.jpg"]; var index=0; setInterval(function(){ var img = document.getElementById('img'); index++; if(index = Array.length){ index = 0; } img.src=imgArr[index]; },1000) }</script></head><body> <img src="img/1.jpg" alt="" id="img"/></body>问题:为什么只有当我设置index>=imgArr.length的时候,循环定时器才能正常运行?当我设置index=imgArr.length的时候,循环定时器不能运行?
添加回答
举报
0/150
提交
取消