<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
*{
margin:0px;
padding:0px;
}
#outer{
margin:50px;
padding:10px;
text-align: center;
}
</style>
<script type="text/javascript">
<!--点击按钮切换图片-->
window.onload=function(){
var prev=document.getElementById("prev");
var nexr=document.getElementById("next");
var img=document.getElementsByTagName("img")[0];
var array=["1.jpg","2.jpg"];
var index=0;
prev.onclick=function () {
// alert("上一张");
index--;
img.src=array[index];
}
next.onclick=function(){
// alert("下一张");
index++;
img.src=array[index];
}
}
</script>
</head>
<body>
<div id="outer">
<img src="1.jpg">
<button id="prev">上一张</button>
<button id="next">下一张</button>
</div>
</body>
</html>
js实现图片查询
最新推荐文章于 2021-06-04 16:15:30 发布