<script language =javascript >
var curIndex=0;
var arr=new Array(); //把图片的URL都放在数组中
arr[0]="1.jpg";
arr[1]="2.jpg";
arr[2]="3.jpg";
arr[3]="4.jpg";
arr[4]="5.jpg";
function next() {
var obj=document.getElementById("showpic");
curIndex+=1;
if(curIndex>arr.length-1){
alert("the last");
curIndex=arr.length-1;
}else{
obj.src="image/"+arr[curIndex];
}
}
function pre(){
var obj=document.getElementById("showpic");
curIndex-=1;
if(curIndex<0){
alert("the first");
curIndex=0;
}else{
obj.src="image/"+arr[curIndex];
}
}
</script>
<img src="image/1.jpg" width="1000" height="800" id="showpic" />
<button onclick="pre();">pre</button>
<button onclick="next();">next</button>