<img id="img" src="a.gif"><script language="javascript"> var list = new Array(); list[0] = new Image(); list[0].src = "a.gif"; list[1] = new Image(); list[1].src = "b.gif"; list[2] = new Image(); list[2].src = "c.gif"; var n = 0; function showpic(){ n = parseInt(Math.random()*(2-0+1)+0); document.getElementById("img").src = list[n].src; } window.setInterval("showpic()",1000); </script>
<html> <script> var imgArray=["1.gif","2.gif","3.gif"]; var orderArray=[]; while(imgArray.length>0){ var n=parseInt(Math.random()*imgArray.length); orderArray.push(imgArray[n]); imgArray.splice(n,1); } window.onload=function(){ window.theImgNumber=0;//全局变量 var theImg=document.getElementById("theImg"); theImg.src=orderArray[theImgNumber]; theImg.onmouseout=function(){ theImgNumber++; this.src=orderArray[theImgNumber%3]; } } </script> <body> <img id="theImg" /> </body> </html>
var list = new Array();
list[0] = new Image();
list[0].src = "a.gif";
list[1] = new Image();
list[1].src = "b.gif";
list[2] = new Image();
list[2].src = "c.gif";
var n = 0;
function showpic(){
n = parseInt(Math.random()*(2-0+1)+0);
document.getElementById("img").src = list[n].src;
}
window.setInterval("showpic()",1000);
</script>
<script>
var imgArray=["1.gif","2.gif","3.gif"];
var orderArray=[];
while(imgArray.length>0){
var n=parseInt(Math.random()*imgArray.length);
orderArray.push(imgArray[n]);
imgArray.splice(n,1);
}
window.onload=function(){
window.theImgNumber=0;//全局变量
var theImg=document.getElementById("theImg");
theImg.src=orderArray[theImgNumber];
theImg.onmouseout=function(){
theImgNumber++;
this.src=orderArray[theImgNumber%3];
}
}
</script>
<body>
<img id="theImg" />
</body>
</html>