<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
*{
margin: 0 auto;
padding: 0;
}
#outer{
margin-top: 20px;
width: 110px;
background: #8A2BE2;
padding: 10px;
text-align: center;
}
</style>
<script type="text/javascript">
window.onload = function(){
var prev =document.getElementById("prev");
var next =document.getElementById("next");
var img = document.getElementsByTagName("img")[0];
var imgArr=["../img/01.png","../img/02.png","../img/03.png","../img/04.png","../img/05.png"]
var index= 0;
var info =document.getElementById("info");
info.innerHTML="当前第"+(index+1)+"张";
prev.οnclick=function(){
index--;
if(index<0){
index=0;
}
img.src=imgArr[index];
info.innerHTML="当前第"+(index+1)+"张";
}
next.οnclick=function(){
index++;
if(index>imgArr.length-1){
index=imgArr.length-1;
alert("最后一张啦")
}
img.src=imgArr[index];
info.innerHTML="当前第"+(index+1)+"张";
}
}
</script>
</head>
<body>
<div id="outer">
<p id="info"></p>
<img src="../img/01.png" alt="打不开"/>
<button id="prev"><上一张</button>
<button id="next">下一张></button>
</div>
</body>
</html>