首页 > 技术文章 > 如何实现图片随机切换

geziwu 2014-03-01 11:12 原文

这个图片随机切换代码也很简单,大家可以自己看代码
<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="images/01.jpg";
width="440";
height="230";
}

if (ad==2) {
url="";
alt="ad2";
banner="images/02.jpg";
width="440";
height="230";
}

if (ad==3) {
url="http://wanhyul931.com";
alt="ad3";
banner="images/03.jpg";
width="440";
height="230";
}

if (ad==4) {
url="http://baomhylc781.com";
alt="ad4";
banner="images/04.jpg";
width="440";
height="230";
}

if (ad==5) {
url="http://xinsd681.com";
alt="ad5";
banner="images/05.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>
');
document.write('</center>');
--></script>

推荐阅读