描述与图像

时间:2015-06-04 23:29:39

标签: javascript html function

我有一个HTML页面,可以在加载时显示随机广告,并且工作正常。所有这些都适用于编号为1-5的随机数发生器。我希望描述与图像匹配

HTML:

<!DOCTYPE html>

<html>

<head>
<title>JavaScript Final Exam</title
<style type="text/css">
.auto-style1 {
    text-align: center;
}
</style>

<script type="text/javascript" src="final.js"></script>
</head>
<body>

<script type="text/javascript">
// calls external function to generate a random integer from 1 to 5
// calls external function to get description of the random ad

var randInt = rNumber;
var rNumber = Math.floor(Math.random() * 2 ) + 1;
document.write("<center>");
document.write('<img src="ad' + rNumber + '.jpg" width="300" height="200" />');
document.write("</a>");
document.write("</center>");
document.write('<br>');
document.write("<center>" + rAd + "</center>");
</script>

<table style="width: 100%">
    <tr>
        <td class="auto-style1" style="width: 50%"><a href="index.html">Home</a></td>
    </tr>
    <tr>
        <td class="auto-style1" style="width: 50%"><a href="CSS.html">CSS                  Page</a></td>
    </tr>
</table>

</body>
</html>

变量rAd是描述应该

的地方

JavaScript的:

function randInt(n) 
{
   randNum = Math.ceil(Math.random()*n);
   return randNum;
}

function adDescription(n) 
{
   var descrip = new Array();
   descrip[1]="[AD] Diamond Health Club - For all your Health Club Needs";
   descrip[2]="[AD] Pixal - Quality Digital Equipment and Accessories";
   descrip[3]="[AD] dHome - Quality Geodesic Domes and Homes";
   descrip[4]="[AD] Dunston Retreat Center - get away";
   descrip[5]="[AD] LanGear - Quality Network Solutions for all your Business Needs";

   return descrip[n];
}

我知道我需要将randInt函数结果传递给rNumber变量,但我不明白它应该如何工作

然后有这个要求,我不知道怎么说

在JavaScript.html文件的注释前面,添加将传输数据的JavaScript代码 存储在adDiscription函数的数组中的一个名为rAd的变量。使用存储在中的值 变量rNumber randInt函数生成以传递给adDiscription函数。

0 个答案:

没有答案