clearIntval()上的调用对象无效

时间:2013-12-19 17:38:09

标签: javascript html

当我调用clearInterval时,我得到一个“无效的调用对象”,我似乎无法弄明白。此错误仅发生在IE上。这是我的代码。谢谢。如果需要更多信息,请告诉我。

<html>
<HEAD>
    <title>Loading, please wait...</title>
    <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"/>
    <script>    
    var ctr = 1;
    var ctrMax = 15; // how many is up to you-how long does your end page take?
    var intervalId;     
    function Begin() 
    {
      //set this page's window.location.href to the target page
        window.location.href = page.html;
        // but make it wait while we do our progress...
        intervalId = window.setInterval("ctr=UpdateIndicator(ctr, ctrMax)", 250);
    }   
    function End() {
    // once the interval is cleared, we yield to the result page (which has been running.  This is where it is breaking)

        window.clearInterval(intervalId);
    }

    function UpdateIndicator(curCtr, ctrMaxIterations) 
    {   

        curCtr += 1;            
        if (curCtr <= ctrMaxIterations) {
            document.getElementById("indicator").style.width =curCtr*25 +"px";
            return curCtr;
        }
        else 
        {
            document.getElementById("indicator").style.width =0;
            return 1;
        }
    }
    </script>
    <link rel="Stylesheet" href="styles/dynamic.css" type="text/css" />
</HEAD>
<body onload="Begin()" onunload="End()">
    <form id="Form1" method="post" runat="server">
        <div align="center">
            <h3>&nbsp;</h3>
            <H3>&nbsp;</H3>
            <H3>&nbsp;</H3>
            <H3>&nbsp;</H3>
            <H3>&nbsp;</H3>
            <H3>Loading Form, please wait...</H3>
        </div>
        <table id="indicator" border="1" cellpadding="0" cellspacing="0" width="0" height="19"
            align="center" class="title">
            <tr>
                <td align="center" width="100%"></td>
            </tr>
        </table>
    </form>
</body>

0 个答案:

没有答案