通过代码实现网页每次展示的图片都不一样。
侵删转自:哈密站长网
Java Script实现的图片随机切换代码,即每次刷新网页显示不同的图片,大家也许见过这样的特效,运行用了JavaScript中的时间函数now.getSeconds()编写而成,并非是使用了Random随机函数,供大家参考和学习。
示例代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>图片随机切换代码演示</title>
</head>
<BODY>
<script language="JavaScript">
var VeryHuo = 5
var now = new Date()
var sec = now.getSeconds()
var ad = sec % VeryHuo;
ad +=1;
if (ad==1){
url="#";
alt="ad1";
banner="/uploads/common/images/wall1.jpg";
width="440";
height="230";
}
if (ad==2) {
url="#";
alt="ad2";
banner="/uploads/common/images/wall2.jpg";
width="440";
height="230";
}
if (ad==3) {
url="#";
alt="ad3";
banner="/uploads/common/images/wall3.jpg";
width="440";
height="230";
}
if (ad==4) {
url="#";
alt="ad4";
banner="/uploads/common/images/wall4.jpg";
width="440";
height="230";
}
if (ad==5) {
url="#";
alt="ad5";
banner="/uploads/common/images/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>
<br /><br /><br /> Veryhuo.COM提示:刷新一下看看!
</BODY>
</HTML><div style="text-align:center;margin:30px 0 0 0;"><hr style="color:#999;height:1px;">如不能显示效果,请按Ctrl+F5刷新本页,更多网页代码:<a href='http://www.veryhuo.com/' target='_blank'>http://www.veryhuo.com/</a></div>
本站所用代码:
<script language="JavaScript">
var VeryHuo = 5
var now = new Date()
var sec = now.getSeconds()
var ad = sec % VeryHuo;
ad +=1;
if (ad==1){
url="http://cpuck.com/cs/";
alt="ad1";
banner="http://cpuck.com/wxm/img/tmcs233.png";
width="100%";
height="100%";
}
if (ad==2) {
url="#";
alt="ad2";
banner="http://cpuck.com/wxm/img/tc.png";
width="100%";
height="100%";
}
if (ad==3) {
url="http://cpuck.com/hc";
alt="ad3";
banner="http://cpuck.com/wxm/img/dy12306.png";
width="100%";
height="100%";
}
if (ad==4) {
url="http://cpuck.com/book/";
alt="ad4";
banner="http://cpuck.com/wxm/img/dybook.png";
width="100%";
height="100%";
}
if (ad==5) {
url="http://cpuck.com/alyf";
alt="ad5";
banner="http://cpuck.com/wxm/img/dyalyf.png";
width="100%";
height="100%";
}
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>