<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>轮播图1</title>
</head>
<body>
< img src="img/img_1.jpg" style="width: 400px;height: 250px;border: 1px solid black;" id="imgTurns">
<script type="text/javascript">
// window.onload = function(){
// 获取id
var imgTurns = document.getElementById("imgTurns");
// 创建数租
var imgArr = ["img/img_1.jpg", "img/img_2.jpg", "img/img_3.jpg"];
// 创建一个索引
var imgIndex = 0;
// 创建函数
function nextImg(){
// 索引自增
imgIndex ++;
if(imgIndex >= imgArr.length){
imgIndex = 0;
}
// 改变img 的路径
imgTurns.src = imgArr[imgIndex];
}
// 插入计时器
setInterval(nextImg,1000);
// }
</script>
</body>
</html>