第二阶段每日汇报20230515
图片切换
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>图片切换</title>
</head>
<style>
#image{
display: block;
width: 500px;
height: 180px;
margin: 10px auto;
}
#next{
margin-left: 350px;
}
</style>
<body>
<img src="./img/123.jpg" id="img" />
<button id="next">next</button>
<button id="prev">prev</button>
<script>
var image = document.getElementById('image');
var next = document.getElementById("next");
var prev = document.getElementById('prev');
var nowIndex = 1;
var count = 6;
next.onclick = function(){
nowIndex = nowIndex+1>count?1:nowIndex+1;
image.src = "img/"+nowIndex+"555.jpg";
}
prev.onclick = function(){
nowIndex = nowIndex<=1?count:nowIndex-1;
image.src = "img/"+nowIndex+"666.jpg";
}
</script>
</body>
</html>