var curIndex = 0; var timeInterval = 3000; var arr = new Array(); arr[0] = "images20150830/new.jpg"; arr[1] = "images20150830/new1.jpg"; setInterval(changeImg,timeInterval); function changeImg() { var map = document.getElementById("map"); if (curIndex == arr.length-1) { curIndex = 0; } else { curIndex += 1; } map.src = arr[curIndex]; }