There are two types of timers in 1 JS: SetInterval and SetTimeout, but in the execution of the code, the timer has the lowest priority, and the rest of the system is not executing, it starts. Examples are: 2 3 <script> 4 window.onload=function () {5 setinterval (function () {6 alert (1); 7},10); 8 for (Var i=0;i<1000000;i++) {9 for (Var j=0;j<1000000;j++) {ten var a=10;11 a*=5; }13}15 Alert (a),};17 </script>18 19 timer, the execution time is 10 milliseconds and the for loop is 1 million milliseconds. Open the page is always in the refresh state, instead of popping 1, refresh for a period of time, the first pop up 50; 1;20 21 22 Second Example: <script>25 window.onload=function () {+ var oMi N=document.getelementbyid (' min '); var Osec=document.getelementbyid (' sec '); var Omin2=document.getelementbyid (' Min2 '); var Osec2=document.getelementbyid (' sec2 '); var start=new Date (); var s2=0;33 s Etinterval (function () {var now=new Date (), S=parseint var ((Now.gettime ()-start.gettime ())/ ); S2+=0.01;40 Omin.innerhtml=parseInt (S/60); osec.innerhtml=s%60;43 omin2.innerhtml=parseint (S2/60); osec2.innerhtml= parseint (s2%60); document.getElementById (' Div1 '); innerhtml=new Date ();};50 </script>51
Some small problems with JS timer