青阁茶心

网站公告

欢迎来到青阁茶心网站


先有卞和慧眼识玉,

才有璞玉磨石成壁。

茶心苦涩遇水甘甜,

网络青阁知己而乐。

青阁茶心座右铭

图片随机切换代码

发表时间:2015/01/11 00:00:00  来源:原创  作者:admin  浏览次数:2662  
字体大小: 【小】 【中】 【大】

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>

效果:

效果请点预览观看

本站源码和一些文章收集于互联网如有侵权或其它问题请及时联系我们,以便及时处理!

张永庆的空间版权所有
copyright 2009-07-20  

( http://www.qgcxjs.com)

All rights reserved 苏ICP备13013770号

苏公网安备 32083002000040号

公众号:青阁茶心