<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{background:#000000;text-align:center;}
h1{margin:40px;color:#FFFFFF;font-weight:bold;}
hr{color:#FFFFFF;margin:20px;}
#Bos{width:500px;height:200px;margin:100px auto;}
</style>
<script>
window.onload=function(){
var curIndex=0;
var arr=new Array();
arr[0]="image/img_1.jpg";
arr[1]="image/img_2.jpg";
arr[2]="image/img_3.jpg";
var img=document.getElementById(‘img‘);
setInterval(ma,1000); //定时器
function ma()
{
if(curIndex==arr.length-1)
{
curIndex=0;
}
else
{
curIndex+=1;
}
img.src=arr[curIndex];
}
}
</script>
</head>
<body>
<h1>图片自动切换</h1>
<hr />
<div id="Bos">
<img src="JavaScript/image/img_1.jpg" id="img" style="width:500px;height:200px;"/>
</div>
</body>
</html>