火狐实现计时器(在线等!)
下面是一段计时器代码,运行后,十秒钟以后会跳转页面。但是在火狐不起作用,请问各位我应该如何修改呢?
<html><head><script>window.onload = function(){ setInterval("a()", 1000);}function a(){ document.getElementById("label1").innerText -= 1; if (document.getElementById("label1").innerText == 0) window.location.href = "http://zhidao.baidu.com";}</script></head><body><span id="label1">10</span></body></html><html><title>倒计时跳转网页</title><head></head><body><script>var cTime = 3;//这个变量是倒计时的秒数设置为10就是10秒function TimeToJump(){window.setTimeout(‘TimeToJump()’,1000);//让程序每秒重复执行当前函数。if(cTime > 0)//判断秒数如果为0{ ShowTime.innerHTML=”倒计时”+cTime+”秒后跳转”;//显示倒计时时间cTime–;//减少秒数}else{Jump_Click();//执行跳转的操作}}function Jump_Click(){window.location = “http://baidu.com”;}TimeToJump()</script><div id=”ShowTime”></div><input type=”button” name=”Jump” onClick=”Jump_Click();” value=”立即跳转”></body></html>
[解决办法]
<html><head><script>window.onload = function(){ setInterval("a()", 1000);}function a(){ document.getElementById("label1").firstChild.nodeValue -= 1; if (document.getElementById("label1").firstChild.nodeValue == 0) window.location.href = "http://zhidao.baidu.com";}</script></head><body><span id="label1">10</span></body></html>