JavaScript图片随机切换代码,页面每载入(刷新)一次,就会随机加载一张图片,每次都有可能不一样的图片,运行用了JavaScript中的时间函数now.getSeconds()编写而成,并非是使用了Random随机函数
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>图片随机切换代码演示</title>
</head>
<BODY>
<script language="JavaScript">
var how_many_ads = 5
var now = new Date()
var sec = now.getSeconds()
var ad = sec % how_many_ads;
ad +=1;
if (ad==1){
url="#";
alt="ad1";
banner="/jscss/demoimg/wall1.jpg";
width="440";
height="230";
}
if (ad==2) {
url="#";
alt="ad2";
banner="/jscss/demoimg/wall2.jpg";
width="440";
height="230";
}
if (ad==3) {
url="#";
alt="ad3";
banner="/jscss/demoimg/wall3.jpg";
width="440";
height="230";
}
if (ad==4) {
url="#";
alt="ad4";
banner="/jscss/demoimg/wall4.jpg";
width="440";
height="230";
}
if (ad==5) {
url="#";
alt="ad5";
banner="/jscss/demoimg/wall5.jpg";
width="440";
height="230";
}
document.write('<center>');
document.write('<a href=\"' + url + '\" target=\"_blank\">');
document.write('<img src=\"' + banner + '\" width=')
document.write(width + ' height=' + height + ' ');
document.write('alt=\"' + alt + '\" border=0><br>');
document.write('</center>');
--></script>
</BODY>
</HTML>
效果: