<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{
margin:0px;
padding:0px;
}
#box1{
width:360px;
background-color: #5F9EA0;
overflow: hidden;
}
#ig{
width:360px;
height:300px;
}
#box1 button{
float: left;
}
#box1 #but01{
margin-left:130.5px;
margin-right:10px;
}
#box1 h1{
text-align: center;
font-family:"微软雅黑";
font-size:30px;
}
</style>
<script>
window.onload=function(){
var but01=document.getElementById("but01");
var but02=document.getElementById("but02");
var box=document.getElementById("box1");
var h1=document.getElementsByTagName("h1")[0];
var ig=document.getElementById("ig");
var imgArr=["img/0.jpg","img/1.jpg","img/2.jpg",
"img/3.jpg","img/4.jpg","img/5.jpg",
"img/6.jpg","img/7.jpg","img/8.jpg",
"img/9.jpg"];
var index=0;
but01.onclick=function(){
index--;
if(index<0){
index=imgArr.length-1;
}else{
index%=imgArr.length;
}
h1.innerHTML="第"+(index+1)+"张";
ig.src=imgArr[index];
};
but02.onclick=function(){
index++;
index%=imgArr.length;
h1.innerHTML="第"+(index+1)+"张";
ig.src=imgArr[index];
};
};
</script>
</head>
<body>
<div id="box1">
<h1>第1张</h1>
<img id="ig" src="img/0.jpg">
<button id="but01">上一张</button>
<button id="but02">下一张</button>
</div>
</body>
</html>