<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> js 定时 打印1到20 </TITLE> <script type="text/javascript" src="assets/plugins/jquery/jquery.min.js"></script> <body> <div id="div1"> </div> </body> </HTML> <script> var n=0; var max=20; window.onload=function(){ var timer = setInterval(function(){ //开启定时器 n++; $("#div1").html(n); if(n == max) { clearInterval(timer); //清除定时器 } },300); }; </script>