<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>图片展示</title>
<style type="text/css">
p {
width: 500px;
height: 500px;
}
img {
max-width: 100%;
border: 2px solid teal;
cursor: pointer;
}
</style>
</head>
<body>
<h1>图片展示</h1>
<p><img src="1.jpg" id="slideimage" name="image_0" alt="home"></p>
<script type="text/javascript">
var images=['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg'];
function nextImage(){
var img = document.getElementById("slideimage");
//这里的split不是表示分隔符,imgname[1]为什么会返回一个数字,img.name 也不是一个数字啊,他前面还有image
var imgname = img.name.split("_");
var index = imgname[1];
if (index == images.length-1) {
index = 0;
}else {
index++;
}
img.src = images[index];
img.name = "image_"+index;
console.log(index);
}
document.getElementById("slideimage").setAttribute("onclick","nextImage()");
</script>
</body>
</html>
相关分类