我的倒数计时器不起作用

时间:2013-03-03 05:29:39

标签: javascript

这是我的Javascript代码:

var run;
var countdown;
var count =14;
var curImage = 1;
function startAdPage() {
run = setInterval("changeAd()"5000);
countdown = setInterval("startCountdown()",1000);
}
function changeAd {
switch (curImage) {
case 1: 
document.images[0].src = "cvb2.gif";
curImage = 2;
break;
case 2: 
document.images[1].src = "cvb3.gif";
curImage = 3;
break;
case 3:
document.images[2].src = "cvb1.gif";
curImage = 1;
break;
}
}
function startCountdown() {
 document.advertisement.ads.value = count;
 --count;
if (0==count;)
window.clearInterval(countdown);
window.clearInterval(run);
count=14;
location.href = "crv2.htm";
}

}

这是我的表格/表格:

<form name="advertisement" method="">
<table>
<tr>
<td><img src="cvb1.gif"></td>
<td>
<p><b><center>Advertisement</center></b></p>
<p><center>The Central Valley Realtors home page will be displayed in <input type="text" name="ads" value="15" size="4" /> seconds.</center></p>
<p><center><a href="cvr2.html">Skip advertisement</a></center></p>
</td>
</tr>
</table>
</form>

文本字段上的值仍然没有倒计时。我的代码有问题吗?

JSFiddle

1 个答案:

答案 0 :(得分:0)

首先,你在这次调用setInterval时错过了一个逗号:

run = setInterval("changeAd()", 5000);