<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="skip"></div>
</body>
</html>
<script>
var skip=document.getElementById("skip");
var count=5;
while(count!=0){
setTimeout(show,1000);
function show(){
skip.innerHTML="还有"+count+"秒跳转";
count--;
}
}
window.location.href = "http://www.baidu.com";
</script>
问题在哪里呢
var skip = document.getElementById("skip");
var count = 5;
function show() {
skip.innerHTML = "还有" + count + "秒跳转";
count--;
if (count < 0)
window.location.href = "http://www.baidu.com";
}
show()
setInterval(show, 1000);
<script>
var skip=document.getElementById("skip");
var count=5;
setTimeout(show,1000);
function show(){
skip.innerHTML="还有"+count+"秒跳转";
count--;
if (count < 0) window.location.href = "http://www.baidu.com"; else setTimeout(show,1000);
}
}