JS 横幅广告
,使用横幅广告来实现页面的不同显示方式。即每一次登入时,将显示不同的页面效果:
如图:
后台代码如下:
代码
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>无标题文档</title>
6 </head>
7
8 <body>
9 <script language="javascript">
10
11 //建立二维数组
12 var banners = new Array(3);
13 for (var i = 0; i < banners.length; i++)
14 banners[i] = new Array(2);
15
16 banners[0][0] = "all.html";
17 banners[0][1] = "tt.jpg";
18
19 banners[1][0] = "yes.html";
20 banners[1][1] = "ww.jpg";
21
22 banners[2][0] = "no.html";
23 banners[2][1] = "12.jpg";
24
25 //显示图片
26
27 var current = Math.round(2*Math.random());
28 document.write("<center><a href='" + banners[current][0] + "'>");
29 document.write("<img src='" + banners[current][1] + "' width=500 height=100></a>");
30 document.write("<br><a href='" + banners[current][0] + "'>按这里</a> </center>");
31
32
33 </script>
34
35 </body>
36 </html>
37
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>无标题文档</title>
6 </head>
7
8 <body>
9 <script language="javascript">
10
11 //建立二维数组
12 var banners = new Array(3);
13 for (var i = 0; i < banners.length; i++)
14 banners[i] = new Array(2);
15
16 banners[0][0] = "all.html";
17 banners[0][1] = "tt.jpg";
18
19 banners[1][0] = "yes.html";
20 banners[1][1] = "ww.jpg";
21
22 banners[2][0] = "no.html";
23 banners[2][1] = "12.jpg";
24
25 //显示图片
26
27 var current = Math.round(2*Math.random());
28 document.write("<center><a href='" + banners[current][0] + "'>");
29 document.write("<img src='" + banners[current][1] + "' width=500 height=100></a>");
30 document.write("<br><a href='" + banners[current][0] + "'>按这里</a> </center>");
31
32
33 </script>
34
35 </body>
36 </html>
37
实现过程:
1,利用二维数组来存储网页和图片。
2,利用数学中的随机函数来进行显示。