<html>
<head>
<title>随机广告</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<script type="text/javascript" language="javascript">
<!--
function randomImg()
{
//设置一个数组用于存放图片URL
var imgArr = new Array();
imgArr[0] = "img/img01.JPG";
imgArr[1] = "img/img02.JPG";
imgArr[2] = "img/img03.JPG";
imgArr[3] = "img/img04.JPG";
//设置一个数组用于存放超链接的URL
var urlArr = new Array();
urlArr[0] = "sample01.htm";
urlArr[1] = "sample02.htm";
urlArr[2] = "sample03.htm";
urlArr[3] = "sample04.htm";
//创建随机数
var ran = Math.random();
//ran为0到1之间的随机数,将其乘以10,得到0到10之间的数
ran = 10 * ran;
//取得ran的整数部分
ran = parseInt(ran);
//取得ran与数组长度的余数,该余数是在0~4之间。
ran = ran % imgArr.length
//获得数组中相应的元素值,赋给Image对象的src属性
document.images[0].src = imgArr[ran];
//获得数组中相应的元素值,赋给Link对象的href属性
document.links[0].href = urlArr[ran];
}
function changImg()
{
//延时5秒,再随机置换图片
window.setTimeout("randomImg()",5000);
}
-->
</script>
</head>
<body>
<a href="sample01.htm" target="_blank"><img src="img/img01.JPG" οnlοad="changImg()" border="0"></a>
</body>
</html>
<head>
<title>随机广告</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<script type="text/javascript" language="javascript">
<!--
function randomImg()
{
//设置一个数组用于存放图片URL
var imgArr = new Array();
imgArr[0] = "img/img01.JPG";
imgArr[1] = "img/img02.JPG";
imgArr[2] = "img/img03.JPG";
imgArr[3] = "img/img04.JPG";
//设置一个数组用于存放超链接的URL
var urlArr = new Array();
urlArr[0] = "sample01.htm";
urlArr[1] = "sample02.htm";
urlArr[2] = "sample03.htm";
urlArr[3] = "sample04.htm";
//创建随机数
var ran = Math.random();
//ran为0到1之间的随机数,将其乘以10,得到0到10之间的数
ran = 10 * ran;
//取得ran的整数部分
ran = parseInt(ran);
//取得ran与数组长度的余数,该余数是在0~4之间。
ran = ran % imgArr.length
//获得数组中相应的元素值,赋给Image对象的src属性
document.images[0].src = imgArr[ran];
//获得数组中相应的元素值,赋给Link对象的href属性
document.links[0].href = urlArr[ran];
}
function changImg()
{
//延时5秒,再随机置换图片
window.setTimeout("randomImg()",5000);
}
-->
</script>
</head>
<body>
<a href="sample01.htm" target="_blank"><img src="img/img01.JPG" οnlοad="changImg()" border="0"></a>
</body>
</html>