<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>对象</title>
<script>
window.onload=function(){
var i=5;
function sum(){
document.getElementsByTagName('span')[0].innerHTML = i;
i--;
if(i==0){
location.assign("https://www.baidu.com");
}
// setTimeout("sum()",1000);
}
// sum();
setInterval("sum()",1000);
}
</script>
</head>
<body>
<h3>操作成功</h3>
<p><span>5</span><span>秒后自动跳转</span><a href="javascript:history.back()">返回</a></p>
<!--
<script>
var i=5;
function sum(){
document.getElementsByTagName('span')[0].innerHTML = i;
i--;
if(i==0){
location.assign("https://www.baidu.com");
}
setTimeout("sum()",1000);
}
sum();
</script>
-->
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>对象</title>
<script>
window.onload=function(){
setInterval(function()
{
var i=5;
document.getElementsByTagName('span')[0].innerHTML = i;
i--;
if(i==0){location.assign("https://www.baidu.com");}
},1000)
}
</script>
</head>
<body>
<h3>操作成功</h3>
<p><span>5</span><span>秒后自动跳转</span><a href="javascript:history.back()">返回</a></p>
</body>
</html>
貌似这样子就没什么错了
定义sum var sum;