慕粉18865550337
2016-09-09 20:30
body里有个id为jishuqi的span标签里面写着一个数,怎么用js代码让这个数很快的加到5000就停止。。。
<script> var calc=document.getElementById('jishuqi'); var number=parseInt(calc.value); if(number>=5000){ document.writeln("It is already 5000,stop it!<br/>"); }else{ for(var i=number;i<=5000;i++){ number += i; } document.writeln("the sum is: "+number+"<br/>"); } </script>
非常感谢!!!
setTimeout:
var num = document.getElementById("jishuqi").innerText; function count() { if(num < 5000) { num++; document.getElementById("jishuqi").innerText = num; setTimeout('count()',30); } } setTimeout('count()',30);
setInterval:
var num = document.getElementById("jishuqi").innerText; var counter = setInterval(function(){ if(num < 5000) { num++; document.getElementById("jishuqi").innerText = num; } else { clearInterval(counter); } },30);
想再快就修改时间喽~
JavaScript进阶篇
468190 学习 · 21891 问题
相似问题