在這個小程式中,需要把images資料夾下圖片的命名設定為有順序的,1、2、3… 複製程式碼 程式碼如下: <BR>var imgnumb = 1; <BR>function imgfor() { <BR>imgnumb ; <BR> document.getElementById('img1').setAttribute('src', 'images/' imgnumb '.jpg'); <BR>if (imgnumb == 5) { //共5張圖片<BR>imgnumb = 0; <BR>} <BR>} <BR>var clearid; <BR>function clearfun() { <BR>clearInterval(clearid); <BR>} <BR>clearid=setInterval(imgfor, 500) <BR> /script> <BR> <BR><body> <BR><img alt="" id="img1" class="style1" src="images/1.jpg" style="max-width:90%" height ="500px" /> <BR><input type="button" value="結束執行" onclick="clearfun();" /> <BR>