问答详情
源自:8-17 编程练习

报错信息是 sum is not defined 求帮助

<!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>


提问者:慕斯卡1577277 2016-06-11 17:50

个回答

  • qq__LZY__0
    2016-06-12 10:18:53

    <!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>

    貌似这样子就没什么错了

  • 下忍
    2016-06-11 22:50:13

    定义sum    var sum;