<script type="text/javascript">
var post_freq = 0.75;
var user_freq = 3.75;
setInterval("document.getElementById(\"total_new\").innerHTML = parseInt(document.getElementById(\"total_new\").innerHTML)+1;document.getElementById(\"total_active\").innerHTML = parseInt(document.getElementById(\"total_active\").innerHTML)+1",1000*post_freq);
setInterval("document.getElementById(\"total_user\").innerHTML = parseInt(document.getElementById(\"total_user\").innerHTML)+1",1000*user_freq);</script>这段JS我是要进入一个Interval然后在函数循环过程中达到一定条件后中止循环;可是调试后发现clearInterval(total_new);不停地执行导致页面很卡。终止条件
<span style="margin:0 0px 0 10px;">total_new:<font id="total_new" style="color:#00AA00">35279</font></span>比如这个就是total_new 的条件
 又比如total_new 从35279一直加到99999后终止
请问大哥们有什么其他方法停止setInterval呢?如何修改上述代码? 

解决方案 »

  1.   

    终止条件 
    <span style="margin:0 0px 0 10px;">total_new: <font id="total_new" style="color:#00AA00">35279 </font> </span>比如这个就是total_new 的条件 
    又比如total_new 从35279一直加到99999后终止 
      

  2.   

    [code=INIFile]
    <script type="text/javascript"> 
    var post_freq = 0.75; 
    var user_freq = 3.75; function  X1(){
    var v=parseInt(document.getElementById("total_new").innerHTML)
    if (v>=35555){clearInterval(t1);return}
    document.getElementById("total_new").innerHTML = v+1;
    document.getElementById("total_active").innerHTML = parseInt(document.getElementById("total_active").innerHTML)+1
    }
    function  X2(){
    var v=parseInt(document.getElementById("total_user").innerHTML)
    if (v>=35555){clearInterval(t2);return}
    document.getElementById("total_user").innerHTML = v+1
    }t1=setInterval("X1()",10*post_freq); 
    t2=setInterval("X2()",1*user_freq); </script> <span style="margin:0 0px 0 10px;">total_new: <font id="total_new" style="color:#00AA00">35279 </font></span><br>
    <span style="margin:0 0px 0 10px;">total_active: <font id="total_active" style="color:#00AA00">35279 </font></span><hr>
    <span style="margin:0 0px 0 10px;">total_user: <font id="total_user" style="color:#00AA00">35279 </font></span><br>[/code]
      

  3.   

    只有一种方法可以停止,楼上已经写了
    不知道楼主有没有看过setInterval和clearInterval怎么使用
      

  4.   

    首先使用setInterval时应该赋值给一个变量,clear相应的对象即可var t1 = window.setInterval(...);
    window.clearInterval(t1);
      

  5.   

    感谢caiying2009  
    Good!不过我还想比如增加到35555,然后过一定时间比如一分钟,又开始以不同的步长增加直到增加到99999999后就终止如何写呢?
      

  6.   

    this?<script type="text/javascript"> 
    var post_freq = 0.75; 
    var user_freq = 3.75; function  X1(k){
    var v=parseInt(document.getElementById("total_new").innerHTML)
    if (v>=k){
    clearInterval(t1);
    if (v<99999999)
    setTimeout(function(){
    t1=setInterval("X1(99999999)",10*post_freq); 
    },60*1000)//=60s=一分钟
    return
    }
    document.getElementById("total_new").innerHTML = v+1;
    document.getElementById("total_active").innerHTML = parseInt(document.getElementById("total_active").innerHTML)+1
    }
    function  X2(k){
    var v=parseInt(document.getElementById("total_user").innerHTML)
    if (v>=k){
    clearInterval(t2);
    if (v<99999999)
    setTimeout(function(){
    t2=setInterval("X2(99999999)",10*post_freq); 
    },60*1000)//=60s=一分钟
    return
    }
    document.getElementById("total_user").innerHTML = v+1
    }t1=setInterval("X1(35555)",10*post_freq); 
    t2=setInterval("X2(35555)",1*user_freq); </script> <span style="margin:0 0px 0 10px;">total_new: <font id="total_new" style="color:#00AA00">35279 </font></span><br>
    <span style="margin:0 0px 0 10px;">total_active: <font id="total_active" style="color:#00AA00">35279 </font></span><hr>
    <span style="margin:0 0px 0 10px;">total_user: <font id="total_user" style="color:#00AA00">35279 </font></span><br>
      

  7.   

    衷心感谢 caiying2009   不过我得分只有这么多了  全部给你吧  有机会请你到我公司来作技术顾问额 WWW.GCOGE.CN
      

  8.   

    方便留下你的联系方式不?pls send to [email protected]  MSN:[email protected]
      

  9.   

    如果你能向我们公司头一份简历过来 那最好不过了 pls send to [email protected]  MSN:[email protected]