<!--实现代码如下-->
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script>
var imageName =new Array("photoA.jpg","photoB.jpg","photoc.jpg","photod.jpg","photoe.jpg","photof.jpg");
var foot =1;//设置角标
window.onload =function(){//匿名函数
var pbtu =document.getElementById("previousButton");
var nbtu =document.getElementById("nextButton");
var img =document.getElementById("img");
nbtu.addEventListener("click",function(){
if(foot>=imageName.length){
foot =0;
}
img.src = "images/" + imageName[foot++];
},false);
pbtu.addEventListener("click",function(){
if(foot<=0){
foot =imageName.length-1;
}
img.src = "images/" + imageName[foot--];
},false);
}
</script>
</head>
<body>
<scan id="info">
<img id="img" src="images/photoa.jpg" height="200px" >
</scan>
<div>
<button id="previousButton" type="button" >上一张</button>
<button id="nextButton" type="button" value="">下一张</button>
</div>
</body>
</html>
利用JavaScript实现在网页上图片上一张下一张的操作
最新推荐文章于 2023-11-01 16:03:11 发布