效果图(图片一直轮流切换):
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>轮播图测试</title>
<script>
window.onload = function(){
window.setInterval(changePic,1000);
}
var num = 1;
function changePic(){
++num;
if(num == 4){
num = 1;
}
var imgElement = document.getElementById("img1");
imgElement.src = "img/"+num+".jpg";
}
</script>
</head>
<body>
<img id="img1" src="img/1.jpg" width="100%" />
</body>
</html>