jquery Deferred demo
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="lib/jquery.js"></script> </head> <body> <div id="demo">this is show demo</div> <script> var wait = function () { var defer = $.Deferred(); var tasks = function () { alert('Lazy Function!'); defer.resolve(); } setTimeout(tasks, 2000); return defer.promise(); }; $.when(wait()).done(function () {console.log('success!')}).fail(function () {console.log('fail')}) </script> </body> </html>
posted on 2014-04-16 12:42 Ijavascript 阅读(175) 评论(0) 编辑 收藏 举报