Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript clearIntval()上的调用对象无效_Javascript_Html - Fatal编程技术网

Javascript clearIntval()上的调用对象无效

Javascript clearIntval()上的调用对象无效,javascript,html,Javascript,Html,当我调用clearInterval时,我得到了一个“无效的调用对象”,而我似乎无法理解它。这个错误只发生在IE上。这是我的代码。非常感谢。如果需要更多信息,请告诉我 <html> <HEAD> <title>Loading, please wait...</title> <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"/> <script>

当我调用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>

正在加载,请稍候。。。
var-ctr=1;
变量ctrMax=15;//多少取决于你,你的结束页需要多长时间?
var有效期;
函数Begin()
{
//将此页面的window.location.href设置为目标页面
window.location.href=page.html;
//但让它等待,而我们做我们的进展。。。
intervalId=window.setInterval(“ctr=UpdateIndicator(ctr,ctrMax)”,250);
}   
函数结束(){
//一旦间隔被清除,我们就进入结果页面(该页面已经运行,这就是它被破坏的地方)
窗口。clearInterval(intervalId);
}
函数更新指示器(curCtr、ctrMaxIterations)
{   
curCtr+=1;

如果(curCtr正在尝试删除
窗口。
,只需调用
clearInterval
。您不需要prefix@RobM.:但这应该没有什么区别。@user:当页面卸载时,不需要清除计时器。清除计时器将作为页面卸载的一部分为您完成,并且对卸载内容有各种限制你可以在加载期间执行
操作,我不能保证你没有遇到任何一个。另外:我强烈建议不要将字符串与
setInterval
setTimeout
一起使用。但这并不是为什么你会出现这种奇怪的错误。@t.J.Crowder,是的,我之前尝试过删除它,而且每个字符串似乎都有问题按预期运行。但是,我正在编辑其他人的代码,除非我必须这样做,否则我不想这样做,但我可能会这样做。我也注意到setInterval中的字符串。哈哈。我也打算更改它。谢谢你的帮助。整个
Begin()
函数没有意义。如果
page.html
事件中有引号,
window.location.href
将立即开始加载新页面,并且不会创建间隔。