<title>Document</title>
</head>
<body OnLoad="swapPic()">
<script language="javascript" type="text/javascript">
var ranl = 0;
var useRand = 0;
images = new Array;
images[1] = new Image();
images[1].src = "images/pic.jpg";
images[2] = new Image();
images[2].src = "images/pic1.jpg";
images[3] = new Image();
images[3].src = "images/pic3.jpg";
images[4] = new Image();
images[4].src = "images/pic4.jpg";
function swapPic(){
var imgnum = images.length-1;
do{
var randnum = Math.random();
randl = Math.round((imgnum-1)*randnum)+1;
}while(randl==useRand);
useRand = randl;
document.randimg.src = images[useRand].src
setTimeout('swapPic()',2000);
}
</script>
<img name ="randimg" src="images/pic.jpg">
</body>
<ml>
使用时候直接替换掉图片地址就Ok