在这个倒计时期间,我需要使用 switch 语句每 5 秒切换一次图片。对于我的一生,我无法弄清楚我做错了什么。
我的提示如下:
在startAdPage()
函数中,包含两条语句:一条语句使用setInterval()
方法调用changeAd()
每五秒命名的函数,另一语句使用setInterval()
方法调用startCountdown()
每秒钟命名的函数。创建该changeAd()
函数,使其每五秒钟将文档正文中的图像与位于第 4 章的 Projects 文件夹中的三个图像交替显示:cvb1.gif、cvb2、gif 和 cvb3.gif。在方法中使用 switch 语句changeAd()
将图像从一个更改为另一个。
创建startCountdown()
函数,以便它将分配给文档正文中的文本字段的值更改为名为 count 的变量的值,每次startCountdown()
执行该函数时,该变量的值都会减少 1(从 15 到 1)。
您可以提供任何帮助我解决此问题的见解将不胜感激。
html>
<head>
<link rel="stylesheet" type="text/css" href="CVR.css"/>
<title>Central Valley Realtors</title>
<script type="text/javascript">
/*[CDATA[*/
function startAdPage(){
window.setInterval("changeAd()", 5000);
window.setInterval("startCountdown()", 1000);
}
function changeAd(){
var cvb = document.getElementById("cvbImage").src;
switch(cvb){
case "images/cvb1.gif":
cvb = "images/cvb2.gif";
break;
case "images/cvb2.gif":
cvb = "images/cvb3.gif";
break;
case "images/cvb3.gif":
cvb = "images/cvb1.gif";
break;
}
}
function startCountdown(){
var count = document.countdown.timer.value;
if(count > 1){
document.countdown.timer.value = count - 1;
}
else{
window.location = "CVR2.html";
}
}
/*]]*/
</script>
</head>
<body onload="startAdPage()">
<table>
<tr>
<td>
<img id="cvbImage" src="images/cvb1.gif" alt=""/>
</td>
<td>
<p>Advertisement</p>
<p>
The Central Valley Realtors homepage will be displayed in
<form name="countdown"><input type="text" name="timer" value="15"/></form>
seconds.
</p>
<p><a href="CVR2.html">Skip Advertisement</a></p>
</td>
</tr>
</table>
</body>