随机生成广告

实现方式有很多的方法,变换路径呀,直接拼接呀,等等等等。

相信很多人都可以实现。今天共享这个,主要是看好了它的思路,一定会用到 MATH.randow();

//随机广告代码
tips = new Array(4);
tips[0] = '<a href="#" target="_blank"><img src="a.jpg" border="0" /></a>';
tips[1] = '<a href="" target="_blank"><img src="b.jpg" border="0" /></a>';
tips[2] = '<a href="" target="_blank"><img src="c.jpg" border="0" /></a>';
tips[3] = '<a href="" target="_blank"><img src="4.jpg" border="0" /></a>';

index = Math.floor(Math.random() * tips.length);
document.write(tips[index]);

数组是好东西!

原文地址:https://www.cnblogs.com/mcat/p/5305295.html