<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
window.onload = function(){
let shang = document.getElementById('shang')
let xia = document.getElementById('xia')
let aimg = document.getElementById('Aimg')
let arr = ["img/1.png","img/2.png","img/3.png"];
let num = 0;
shang.onclick = function(){
if(num < 0){
num = arr.length - 1;
}
aimg.src = arr[num]
num-=1
}
xia.onclick = function(){
if(num>=2){
num = 0
}
num+=1
aimg.src = arr[num]
}
}
</script>
<style type="text/css">
#top{
border: 1px solid #FF0000;
width: 600px;
height: 500px;
}
</style>
</head>
<body>
<div id="top">
<img src="img/1.png" width="600px" height="500px" id = "Aimg">
</div>
<button type="button" id="shang">上一张</button>
<button type="button" id="xia">下一章</button>
</body>
</html>
js 函数数组练习
最新推荐文章于 2024-11-02 12:42:04 发布