1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">  
  2. <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title> jQuery中setTimeout的几种使用方法 </title>  
  3. <script src="jquery.js"></script>  
  4. <script language="JavaScript">  
  5. //显示在页面上函数  
  6. function log(s){  
  7.     $('#div_debug').append(s+'<br>');  
  8. }  
  9.   
  10. //以下是 setTimeout 在 jQuery 中的用法  
  11. function funA(){ 
  12.     log('funA...');  
  13.     setTimeout('funA()', 1000);  
  14. }  
  15.   
  16. jQuery(document).ready(function($){  
  17.     //用法1 : 把要调用的函数写在ready外面,使它成为全局函数  
  18.     funA();  
  19.   
  20.     //用法2 : 直接写函数名,不能带括号也不能带引号,适合没有参数的函数  
  21.     function funB(){  
  22.         log('funB...');  
  23.         setTimeout(funB, 1000);  
  24.     }  
  25.     funB();  
  26.   
  27.     //用法3 : 通过调用匿名函数来执行,适合有带参数的函数  
  28.     function funC(v){  
  29.         log('funC...'+v);  
  30.         setTimeout(function(){funC(v+1)}, 1000);  
  31.     }  
  32.     funC(1);  
  33.   
  34.     //用法4 : 通过在jQuery命名空间上增加函数,调用起来更方便  
  35.     $.extend({  
  36.         funD:function(v){  
  37.             log('funD...'+v);  
  38.             setTimeout("$.funD("+(v+1)+")",1000);  
  39.         }  
  40.     });  
  41.     $.funD(101);  
  42. });  
  43. </script>  
  44. /////////////////////////////////////////////////////////////////////////////  
  45. </head><body>  
  46. <div id="div_debug"></div>  
  47. </body>  
  48. </html>