setInterval、控制停止和继续
在只用js之前,一定要引入jar包
<script src="../js/jquery-1.4.2.js" type="text/javascript"></script>
<div id="one"> 0 </div> <script type="text/javascript"> var one = document.getElementById("one"); var i = 0; var dt = setInterval(function(){ one.innerText=i; i++; }, 100); function stop(){ clearInterval(dt); } function star(){ dt = setInterval(function(){ one.innerText=i; i++; }, 100); } </script> <input type="button" onclick="stop()" value="停止"/> <input type="button" onclick="star()" value="开始"/>