註:images資料夾下圖片的命名是從1~5.jpg有規律的宣告的var array = [1, 2, 3, 4, 5]; 這個陣列存放的是圖片的名稱 複製代碼 代碼如下: <BR>img <BR>{ <BR>width: 200px; <BR>height: 200px; <BR>} <BR> <BR>$(function () { <BR>var array = [1, 2, 3, 4, 5]; <BR>var count = 0; <BR>$('#Button1').click(function () { <BR>if (count > 0) { <BR>count--; <BR>$('img').attr('src','images/' array[count] '.jpg'); <BR>} <BR>}) <BR>$(' #Button2').click(function () { <BR>if (count <4) { <BR>count ; <BR>$('img').attr('src', 'images/' array[count] '.jpg'); <BR>} <BR>}) <BR>}) <BR> 複製代碼 代碼如下: <BR>#mydiv <BR>{ <BR>position: absolute; <BR>width: 500px; <BR>height: 400px; <BR>top: 50%; <BR>left: 50%; <BR>margin-top: -200px; <BR>margin-left: -290px; <BR>} <BR>img <BR>{ <BR>width:} <BR>img <BR>{ <BR>width: 480pidth: 480p; height: 380px; <BR>} <BR> <BR>$(function () { <BR>//第一種方法<BR>/* <BR>$('#btn1').toggle(function () { $('img') .attr('src', 'images/1.jpg'); }, <BR>function () { $('img').attr('src', 'images/2.jpg'); }, <BR>function () { $('img').attr('src', 'images/3.jpg'); }, <br>function () { $('img').attr('src', 'images/4.jpg'); }, <br>function () { $('img').attr('src', 'images/5.jpg'); }); <BR><BR>$ ('#btn2').toggle(function () { $('img').attr('src', 'images/5.jpg'); }, <BR>function () { $('img') .attr('src', 'images/4.jpg'); }, <BR>function () { $('img').attr('src', 'images/3.jpg'); }, <BR>function () { $('img').attr('src', 'images/2.jpg'); }, <br>function () { $('img').attr('src', 'images/1.jpg'); }); <br>*/ <br><br>//第二種方法<BR><BR>var array = [1, 2, 3, 4, 5, 6 ]; <BR>var count = 0; <BR>//後退<BR>$('#btn1').click(function () { <BR>if (count > 0) { <BR>count--; <BR>$('img').attr('src', 'images/' array[count] '.jpg'); <BR>} <BR>}) <BR>//前進<BR>$( '#btn2').click(function () { <BR>if (count < 5) { <BR>count ; <BR>$('img').attr('src', 'images/' array[count ] '.jpg'); <br>} <br>}) <BR><BR>}) <BR> td>