<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<h2>操作成功!</h2>
<p>
<b id = "countDown">3</b>秒后回到主页<a href="javascript:goBack();">返回</a>
</p>
<script type="text/javascript">
var seconds = document.getElementById("countDown");
var num = 3;
function jump(){
if(num>0){
num--;
seconds.innerHTML = num;
if(num == 1){
window.location.href="https://www.baidu.com";
}
}else{
clearInterval("jump()");
} }
setInterval("jump()",1000);
function goBack(){
window.history.back();
}
</script>
</body>
</html>
<!DOCTYPE html> <html> <head> <title>浏览器对象</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <h2>操作成功!</h2> <p> <b id = "countDown">3</b>秒后回到主页<a href="javascript:goBack();">返回</a> </p> <script type="text/javascript"> var num = document.getElementById("countDown").innerHTML; function jump(){ --num; document.getElementById("countDown").innerHTML=num; if(num>0){ if(num == 1){ window.location.assign("https://www.baidu.com"); } }else{ clearInterval("jump()"); } } setInterval("jump()",1000); function goBack(){ window.history.back(); } </script> </body> </html>
问题自减是--num;
这里 var seconds = document.getElementById("countDown");
var num = 3;
function jump(){
if(num>0){
num--;
seconds.innerHTML = num;
if(num == 1){
window.location.href="https://www.baidu.com";
}
}else{
clearInterval("jump()");
} }
你获取了值 但是 你没处理 返回的 所以返回的 还是3
这句话是获取id而已