我尝试在X秒过后将用户重定向到另一个页面,这是我的尝试,但是我得到一个错误页面并且无法执行任何操作:
<span id="zeit"></span>
<script>
var timer=9;
while (timer>0) {
setTimeout(function(){
timer = timer - 1;
document.getElementById("zeit").innerHTML = timer;
},1000);
}
window.location.href = "home";
</script>
我做错了什么?
解决方案:
var timer=9;
setInterval(function(){
timer = timer - 1;
document.getElementById("zeit").innerHTML = timer;
if (timer===0) window.location.href = "home";
},1000);