利用setTimeout函數

 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Dynamic Image Lab</title>
</head>
<body>

<p>...</p>

<a id="imgshref" href="http://oakland.athletics.mlb.com/" target="_blank">
<img src="images/oak.gif" id="imgs" border="0" />
</a>

<p>...</p>

<script type="text/javascript">

 

function setImage()
{
var img = new Array();
var url = new Array();
img[0] = "images/chc.gif"; url[0] = "http://chicago.cubs.mlb.com/";
img[1] = "images/oak.gif"; url[1] = "http://oakland.athletics.mlb.com/";
img[2] = "images/sd.gif"; url[2] = "http://sandiego.padres.mlb.com/";
img[3] = "images/was.gif"; url[3] = "http://washington.nationals.mlb.com/";

var iImage = Math.floor(Math.random() * img.length);
document.getElementById("imgs").src = img[iImage];
document.getElementById("imgshref").href = url[iImage];

setTimeout("setImage()",1000);

}

setImage();

</script>

</body>
</html>

arrow
arrow
    文章標籤
    圖片
    全站熱搜
    創作者介紹
    創作者 Y銘 的頭像
    Y銘

    ㄚ銘老師的部落格

    Y銘 發表在 痞客邦 留言(0) 人氣()