- <!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">
- <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title> jQuery中setTimeout的几种使用方法 </title>
- <script src="jquery.js"></script>
- <script language="JavaScript">
- //显示在页面上函数
- function log(s){
- $('#div_debug').append(s+'<br>');
- }
- //以下是 setTimeout 在 jQuery 中的用法
- function funA(){
- log('funA...');
- setTimeout('funA()', 1000);
- }
- jQuery(document).ready(function($){
- //用法1 : 把要调用的函数写在ready外面,使它成为全局函数
- funA();
- //用法2 : 直接写函数名,不能带括号也不能带引号,适合没有参数的函数
- function funB(){
- log('funB...');
- setTimeout(funB, 1000);
- }
- funB();
- //用法3 : 通过调用匿名函数来执行,适合有带参数的函数
- function funC(v){
- log('funC...'+v);
- setTimeout(function(){funC(v+1)}, 1000);
- }
- funC(1);
- //用法4 : 通过在jQuery命名空间上增加函数,调用起来更方便
- $.extend({
- funD:function(v){
- log('funD...'+v);
- setTimeout("$.funD("+(v+1)+")",1000);
- }
- });
- $.funD(101);
- });
- </script>
- /////////////////////////////////////////////////////////////////////////////
- </head><body>
- <div id="div_debug"></div>
- </body>
- </html>
转载于:https://blog.51cto.com/jackey088/742545