例子:图片轮播
<div style="width:1000px; height:250px; margin-top:30px">
<img src="img/11.jpg" width="1000" height="250" />
<img src="img/22.png" width="1000" height="250" style="display:none" />
<img src="img/33.png" width="1000" height="250" style="display:none" />
<img src="img/44.png" width="1000" height="250" style="display:none" />
</div>
<script type="text/javascript">
window.setInterval("Huan()",2000);
//找到图片的最大索引
var n = document.getElementsByTagName("img").length-1;
//存当前图片的索引
var d =0;
//换图
function Huan()
{
//找到所有图片
var attr = document.getElementsByTagName("img");
//当前索引加1
d++;
//判断索引是否超出范围
if(d>n)
{
d = 0;
}
//换图
//让所有隐藏
for(var i=0;i<=n;i++)
{
attr[i].style.display = "none";
}
//让该索引的显示
attr[d].style.display = "block";
}
</script>