timerID定义成全局变量
timerID分别指向两个setTimeout,clearTimeout只能去除掉1个,多定义个timerid看看

解决方案 »

  1.   

    clearTimeout(timerID);
    改为if(timerID<>""){
    clearTimeout(timerID);
    }
      

  2.   

    setTimeout有没有必要,用一个清除一个?(少的情况下)我现在有很多setTimeout,应该定义很多timerID?上面的代码运行1,2次,没什么问题,会循环运行很多次,奇怪的是根本运行不到最后,大概3,4次的时候就出错了。
      

  3.   

    timerID1 = setTimeout("",20000); 
    timerID2 = setTimeout("",20000); 
    timerID3 = setTimeout("",20000); 执行完按序号对应清除?是这个意思吧。
      

  4.   

    这段代码是放在循环中执行的,大概需要重复30-50次。timerID = setTimeout("location.href = 'index.html';clearTimeout(timerID);",20000);最后这句就是循环处,location.href = 'x.asp?goto=开始下一轮循环';
      

  5.   

    下一轮循环中,更换数组的值:url_2[0] = "http://www.xxx.com/"; 
    url_2[1] = "http://www.xxx.com/"; 
    url_2[2] = "http://www.xxx.com/"; 
    url_2[3] = "http://www.xxx.com/"; 
    url_2[4] = "http://www.xxx.com/"; 这些是跟着循环变的。数组数量太大,一次执行,很慢,IE受不了,所以分开处理了。每次处理5个,一个数组5个元素。
      

  6.   

    这是下一个循环的中的代码:(后面的循环都是这样的,只是数字不同。)麻烦帮忙查看一下。
    <script type="text/javascript">
    var url_3 = new Array(5);
    url_3[0] = "http://www.xxx.com/";
    url_3[1] = "http://www.xxx.com/";
    url_3[2] = "http://www.xxx.com/";
    url_3[3] = "http://www.xxx.com/";
    url_3[4] = "http://www.xxx.com/";
    var t1 = null;
    var t2 = null;
    var i = 0;
    var j = getCookie("count");
    function Output() {
    clearTimeout(t1);
    $("ifm").src = url_3[i];
    $("num").innerHTML = j;
    setCookie("count",j);
    i++;j++;
    t1 = setTimeout("Output();",20000);
    if (i == 5) {
    url_3 = null;CollectGarbage();
    t2 = setTimeout("location.href = '?do=visit&arrnum=2';clearTimeout(t2);",20000);
    }
    }
    Output();
    </script>
      

  7.   

    在朋友机器里是这样报错:0x49e85567 指令引用的0x08bf1184 内存。该内存不能为“read”。
      

  8.   

    <%
    '网址都保存在txt文本文件里了,不是数据库的。
    '有N个txt文件保存网址。1.txt 2.txt 3.txt
    sub visit
    dim arraynum:arraynum = q("arraynum",3)'循环标记
    dim name:name = getname(dbpath)
    dim arrname:arrname = split(name,"*")
    if cint(arraynum - ubound(arrname)) = 1 then'判断循环是否结束
    session.abandon
    response.write("<script type=""text/javascript"">delCookie(""count"");alert(""完成!"");</script>")
    response.end
    end if
    dim list:list = readfile(dbpath & arrname(arraynum))'读取单个txt中的网址
    dim item:item = split(list,chr(13) & chr(10))
    dim html,i,j:j = ubound(item)
    html = "<script type=""text/javascript"">" & chr(13) & chr(10)
    html = html & "var url = new Array(" & j + 1 & ");" & chr(13) & chr(10)
    for i = 0 to j
    html = html & "url[" & i & "] = """ & item(i) & """;" & chr(13) & chr(10)
    next
    if arraynum = 0 then
    session("count") = 0
    html = html & "setCookie(""count"",1);" & chr(13) & chr(10)
    end if
    html = html & "var t1 = null;" & chr(13) & chr(10)
    html = html & "var t2 = null;" & chr(13) & chr(10)
    html = html & "var i = 0;" & chr(13) & chr(10)
    html = html & "var j = getCookie(""count"");" & chr(13) & chr(10)
    html = html & "function Output() {" & chr(13) & chr(10)
    'html = html & "clearTimeout(t1);" & chr(13) & chr(10)
    html = html & "$(""ifm"").src = url[i];" & chr(13) & chr(10)
    html = html & "$(""num"").innerText = j;" & chr(13) & chr(10)
    html = html & "setCookie(""count"",j);" & chr(13) & chr(10)
    html = html & "i++;" & chr(13) & chr(10)
    html = html & "j++;" & chr(13) & chr(10)
    html = html & "t1 = setTimeout(""Output();""," & refreshtime * 1000 & ");" & chr(13) & chr(10)
    html = html & "if (i == " & j + 1 & ") {" & chr(13) & chr(10)
    session("count") = session("count") + 1
    html = html & "t2 = setTimeout(""location.href = '?do=visit&arraynum=" & session("count") & "';clearTimeout(t2);""," & refreshtime * 1000 & ");" & chr(13) & chr(10)
    html = html & "}" & chr(13) & chr(10)
    html = html & "}" & chr(13) & chr(10)
    html = html & "Output();" & chr(13) & chr(10)
    html = html & "</script>"
    response.write html
    end sub
    %>
      

  9.   

    clearTimeout(t1);非常奇怪,我把这句注销了,居然半天没有报错了。按道理说,清空计时器应该是好的,可以现在不用清空反倒不出错了。麻烦帮忙看看。谢谢!
      

  10.   

    setCookie(""count"",1);" 
    getCookie(""count"");" 
    使用COOKIE???
      

  11.   

    timerID = setTimeout(function(){location.href = 'index.html';clearTimeout(timerID);},20000); 
      

  12.   

    cookies 用来计数的。我先试试楼上的办法。
      

  13.   

    改了,是在运行,看不到效果了。这样与把IFRAME区域缩小是一样意思??
      

  14.   

    使用IE7测试没有见到你说的现象啊。
    可以到
    http://dotnet.aspx.cc/exam/a.htm进行测试一下
    <body>
    <iframe id="ifm" width="200" height="500" src=""></iframe> 
    <div id=num></div><script type="text/javascript"> 
    function $(id)
    {
    return document.getElementById(id)
    }
    var url_2 = new Array(5); 
    url_2[0] = "http://www.g.cn/"; 
    url_2[1] = "http://www.g.cn/"; 
    url_2[2] = "http://www.g.cn/"; 
    url_2[3] = "http://www.g.cn/"; 
    url_2[4] = "http://www.g.cn/"; 
    var i = 0; 
    var j = 1; 
    var timerID = null;
    function Output() { 
    if(timerID) clearTimeout(timerID); 
    $("ifm").src = url_2[i]; 
    $("num").innerHTML = j; 
    delete url_2[i]; 
    i++;j++; 
    timerID = setTimeout("Output();",2000); 
    if (i == 5) { 
    url_2 = null;CollectGarbage(); 
    timerID = setTimeout("location.href = 'a.htm';clearTimeout(timerID);",2000); 


    Output(); 
    </script> 
    </body>
      

  15.   

    if(timerID) clearTimeout(timerID); 
    之前交你你加这个测试,你测试没?
      

  16.   

    可以了http://www.600z.cn/test/index.asp
      

  17.   

    <script type="text/javascript"> 
    var timerID;
    var url_2 = new Array(5); 
    url_2[0] = "http://www.xxx.com/"; 
    url_2[1] = "http://www.xxx.com/"; 
    url_2[2] = "http://www.xxx.com/"; 
    url_2[3] = "http://www.xxx.com/"; 
    url_2[4] = "http://www.xxx.com/"; 
    var i = 0; 
    var j = 1; 
    function Output() { 
    clearTimeout(timerID); 
    $("ifm").src = url_2[i]; 
    $("num").innerHTML = j; 
    delete url_2[i]; 
    i++;j++; 
    timerID = setTimeout("Output();",20000); 
    if (i == 5) { 
    url_2 = null;CollectGarbage(); 
    timerID = setTimeout("location.href = 'index.html';clearTimeout(timerID);",20000); 


    Output(); 
    </script> 
      

  18.   

    如果iframe里访问的页面,JS客户端代码过多,消耗比较大,有什么办法处理没?现在访问的是HTML页,没消耗多少资源。