<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呢?如何修改上述代码?
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呢?如何修改上述代码?
解决方案 »
- js 复制内容到剪贴板 需要在遨游下可用
- extjs girdpanel中的数据为何不显示?专家帮帮忙!
- 网易笔试题疑惑
- javaScript 数据转换 ArrayList
- if (!c4csel.compare(frameWindow.document)) return true;
- 提交表单能用js window.open吗?
- 如何算Json的长度
- 本人想学习 JavaScript 高手们推荐们书啊!!
- 如何让 页面 的大小和 TABLE 的大小一样
- 如何正确输出<img src="UploadFile/2004322204213185.JPG">这行代码?
- 遨游浏览器上,怎么用js让它关闭时弹出提示,像ie那样
- js如何调用linux下的c函数
<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后终止
<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]
不知道楼主有没有看过setInterval和clearInterval怎么使用
window.clearInterval(t1);
Good!不过我还想比如增加到35555,然后过一定时间比如一分钟,又开始以不同的步长增加直到增加到99999999后就终止如何写呢?
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>