etTimeout来实现setInterval
etTimeout来实现setInterval
1 <script type="text/javascript"> 2 function interval(func, w, t){ 3 var interv = function(){ 4 if(typeof t === "undefined" || t-- > 0){ 5 setTimeout(interv, w); 6 try{ 7 func.call(null); 8 } 9 catch(e){ 10 t = 0; 11 throw e.toString(); 12 } 13 } 14 }; 15 16 setTimeout(interv, w); 17 }; 18 19 </script>