<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>图片轮播</title>
<style type="text/css">
div{
width:900px;
height:400px;
margin:0 auto;
}
div img{
width:900px;
height:400px;
}
</style>
<script type="text/javascript">
function init(){
// window.setTimeout(changeImg,2000);//延迟2秒调用一次changeImg方法。
window.setInterval(changeImg,2000);//循环,每隔2秒调用一次changeImg方法。
}
var index = 1;
function changeImg(){
myimg = document.getElementById("myimg");
index++;
if(index > 2){
index = 1;
}
myimg.src = "img/" + index + ".png";
}
</script>
</head>
<body onload="init()">
<div>
<img src="img/1.png" id="myimg" />
</div>
</body>
</html>
1,怎么自动调用某个函数(自动轮播)
setInterval(functionName,millisec);