注: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: 480px; <BR>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>