<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title></title>
<style>
* {
margin: 0px;
padding: 0px;
}
.content {
width: 1200px;
height: 300px;
margin: 20px auto;
position: relative;
}
#images {
width: 100%;
height: 100%;
}
.c-title {
width: 100%;
height: 30px;
line-height: 30px;
text-align: center;
background-color: rgba(0, 0, 0, .5);
position: absolute;
left: 0px;
bottom: 0px;
}
</style>
</head>
<body>
<div class="content">
<img id="images" src="images/a.jpg" />
<p class="c-title">我是第1个</p>
</div>
</body>
</html>
<script>
setInterval(function () {
arr = ["a.jpg", "b.jpg", "c.jpg", "d.jpg", "e.jpg"];
key = Math.floor(Math.random() * arr.length);
val = arr[key];
var mz = document.getElementById('images');
mz.src = "images/" + val;
document.getElementsByClassName("c-title")[0].innerHTML = "我是第" + key + "个";
}, 2000);
</script>