{"id":4744,"date":"2016-01-11T22:32:37","date_gmt":"2016-01-11T14:32:37","guid":{"rendered":"https:\/\/sdeno.com\/?p=4744"},"modified":"2016-01-11T22:32:37","modified_gmt":"2016-01-11T14:32:37","slug":"%e4%bd%bf%e7%94%a8-jquery-deferred-%e5%92%8c-promise-%e5%88%9b%e5%bb%ba%e5%93%8d%e5%ba%94%e5%bc%8f%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=4744","title":{"rendered":"\u4f7f\u7528 jQuery Deferred \u548c Promise \u521b\u5efa\u54cd\u5e94\u5f0f\u5e94\u7528\u7a0b\u5e8f"},"content":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\uff0c\u6211\u4eec\u4e00\u8d77\u63a2\u7d22\u4e00\u4e0b JavaScript \u4e2d\u7684 Deferred \u548c Promise \u7684\u6982\u5ff5\uff0c\u5b83\u4eec\u662f JavaScript \u5de5\u5177\u5305\uff08\u5982Dojo\u548cMochiKit\uff09\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u4e00\u4e2a\u529f\u80fd\uff0c\u6700\u8fd1\u4e5f\u9996\u6b21\u4eae\u76f8\u4e8e \u6d41\u884c\u7684 JavaScript \u5e93 jQuery\uff08\u5df2\u7ecf\u662f1.5\u7248\u672c\u7684\u4e8b\u60c5\u4e86\uff09\u3002 Deferred \u63d0\u4f9b\u4e86\u4e00\u4e2a\u62bd\u8c61\u7684\u975e\u963b\u585e\u7684\u89e3\u51b3\u65b9\u6848\uff08\u5982 Ajax \u8bf7\u6c42\u7684\u54cd\u5e94\uff09\uff0c\u5b83\u521b\u5efa\u4e00\u4e2a \u201cpromise\u201d \u5bf9\u8c61\uff0c\u5176\u76ee\u7684\u662f\u5728\u672a\u6765\u67d0\u4e2a\u65f6\u95f4\u70b9\u8fd4\u56de\u4e00\u4e2a\u54cd\u5e94\u3002\u5982\u679c\u60a8\u4e4b\u524d\u6ca1\u6709\u63a5\u89e6\u8fc7 \u201cpromise\u201d\uff0c\u6211\u4eec\u5c06\u4f1a\u5728\u4e0b\u9762\u505a\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n<p style=\"color: #393939;\">\u62bd\u8c61\u6765\u8bf4\uff0cdeferreds \u53ef\u4ee5\u7406\u89e3\u4e3a\u8868\u793a\u9700\u8981\u957f\u65f6\u95f4\u624d\u80fd\u5b8c\u6210\u7684\u8017\u65f6\u64cd\u4f5c\u7684\u4e00\u79cd\u65b9\u5f0f\uff0c\u76f8\u6bd4\u4e8e\u963b\u585e\u5f0f\u51fd\u6570\u5b83\u4eec\u662f\u5f02\u6b65\u7684\uff0c\u800c\u4e0d\u662f\u963b\u585e\u5e94\u7528\u7a0b\u5e8f\u7b49\u5f85\u5176\u5b8c\u6210\u7136\u540e\u8fd4\u56de\u7ed3\u679c\u3002deferred\u5bf9 \u8c61\u4f1a\u7acb\u5373\u8fd4\u56de\uff0c\u7136\u540e\u4f60\u53ef\u4ee5\u628a\u56de\u8c03\u51fd\u6570\u7ed1\u5b9a\u5230deferred\u5bf9\u8c61\u4e0a\uff0c\u5b83\u4eec\u4f1a\u5728\u5f02\u6b65\u5904\u7406\u5b8c\u6210\u540e\u88ab\u8c03\u7528\u3002<\/p>\n<h4 style=\"font-weight: bold;\">Promise<\/h4>\n<p style=\"color: #393939;\">\u3000\u3000\u4f60\u53ef\u80fd\u5df2\u7ecf\u9605\u8bfb\u8fc7\u4e00\u4e9b\u5173\u4e8epromise\u548cdeferreds\u5b9e\u73b0\u7ec6\u8282\u7684\u8d44\u6599\u3002\u5728\u672c\u7ae0\u8282\u4e2d\uff0c\u6211\u4eec\u5927\u81f4\u4ecb\u7ecd\u4e0bpromise\u5982\u4f55\u5de5\u4f5c\uff0c\u8fd9\u4e9b\u5728\u51e0\u4e4e\u6240\u6709\u7684\u652f\u6301deferreds\u7684javascript\u6846\u67b6\u4e2d\u90fd\u662f\u9002\u7528\u7684\u3002<\/p>\n<p style=\"color: #393939;\">\u3000\u3000\u4e00\u822c\u60c5\u51b5\u4e0b\uff0cpromise\u4f5c\u4e3a\u4e00\u4e2a\u6a21\u578b\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5728\u8f6f\u4ef6\u5de5\u7a0b\u4e2d\u63cf\u8ff0\u5ef6\u65f6\uff08\u6216\u5c06\u6765\uff09\u6982\u5ff5\u7684\u89e3\u51b3\u65b9\u6848\u3002\u5b83\u80cc\u540e\u7684\u601d\u60f3\u6211\u4eec\u5df2\u7ecf\u4ecb\u7ecd\u8fc7\uff1a\u4e0d\u662f\u6267\u884c\u4e00\u4e2a\u65b9\u6cd5\u7136\u540e\u963b\u585e\u5e94\u7528\u7a0b\u5e8f\u7b49\u5f85\u7ed3\u679c\u8fd4\u56de\uff0c\u800c\u662f\u8fd4\u56de\u4e00\u4e2apromise\u5bf9\u8c61\u6765\u6ee1\u8db3\u672a\u6765\u503c\u3002<\/p>\n<p style=\"color: #393939;\">\u3000\u3000\u4e3e\u4e00\u4e2a\u4f8b\u5b50\u4f1a\u6709\u52a9\u4e8e\u7406\u89e3\uff0c\u5047\u8bbe\u4f60\u6b63\u5728\u5efa\u8bbe\u4e00\u4e2aweb\u5e94\u7528\u7a0b\u5e8f\uff0c \u5b83\u5f88\u5927\u7a0b\u5ea6\u4e0a\u4f9d\u8d56\u7b2c\u4e09\u65b9api\u7684\u6570\u636e\u3002\u90a3\u4e48\u5c31\u4f1a\u9762\u4e34\u4e00\u4e2a\u5171\u540c\u7684\u95ee\u9898\uff1a\u6211\u4eec\u65e0\u6cd5\u83b7\u6089\u4e00\u4e2aAPI\u54cd\u5e94\u7684\u5ef6\u8fdf\u65f6\u95f4\uff0c\u5e94\u7528\u7a0b\u5e8f\u7684\u5176\u4ed6\u90e8\u5206\u53ef\u80fd\u4f1a\u88ab\u963b\u585e\uff0c\u76f4\u5230\u5b83\u8fd4\u56de \u7ed3\u679c\u3002Deferreds \u5bf9\u8fd9\u4e2a\u95ee\u9898\u63d0\u4f9b\u4e86\u4e00\u4e2a\u66f4\u597d\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u5b83\u662f\u975e\u963b\u585e\u7684\uff0c\u5e76\u4e14\u4e0e\u4ee3\u7801\u5b8c\u5168\u89e3\u8026 \u3002<\/p>\n<p style=\"color: #393939;\">\u3000\u3000Promise\/A\u63d0\u8bae\u2019\u5b9a\u4e49\u4e86\u4e00\u4e2a\u2019then\u2018\u65b9\u6cd5\u6765\u6ce8\u518c\u56de\u8c03\uff0c\u5f53\u5904\u7406\u51fd\u6570\u8fd4\u56de\u7ed3\u679c\u65f6\u56de\u8c03\u4f1a\u6267\u884c\u3002\u5b83\u8fd4\u56de\u4e00\u4e2apromise\u7684\u4f2a\u4ee3\u7801\u770b\u8d77\u6765\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">promise\u00a0=\u00a0callToAPI(\u00a0arg1,\u00a0arg2,\u00a0&#8230;);<\/li>\n<li style=\"color: #5c5c5c;\">promise.then(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0futureValue\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\"><span class=\"comment\" style=\"color: #008200;\">\/*\u00a0handle\u00a0futureValue\u00a0*\/<\/span><\/li>\n<li style=\"color: #5c5c5c;\">});<\/li>\n<li style=\"color: #5c5c5c;\">promise.then(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0futureValue\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0<span class=\"comment\" style=\"color: #008200;\">\/*\u00a0do\u00a0something\u00a0else\u00a0*\/<\/span><\/li>\n<li style=\"color: #5c5c5c;\">\u00a0});<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u6b64\u5916\uff0cpromise\u56de\u8c03\u4f1a\u5728\u5904\u4e8e\u4ee5\u4e0b\u4e24\u79cd\u4e0d\u540c\u7684\u72b6\u6001\u4e0b\u6267\u884c\uff1a<\/p>\n<ul style=\"color: #393939;\">\n<li>resolved\uff1a\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6570\u636e\u662f\u53ef\u7528<\/li>\n<li>rejected\uff1a\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u51fa\u73b0\u4e86\u9519\u8bef\uff0c\u6ca1\u6709\u53ef\u7528\u7684\u503c<\/li>\n<\/ul>\n<p style=\"color: #393939;\">\u3000\u3000\u5e78\u8fd0\u7684\u662f\uff0c&#8217;then&#8217;\u65b9\u6cd5\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570\uff1a\u4e00\u4e2a\u7528\u4e8epromise\u5f97\u5230\u4e86\u89e3\u51b3\uff08resolved\uff09\uff0c\u53e6\u4e00\u4e2a\u7528\u4e8epromise\u62d2\u7edd\uff08rejected\uff09\u3002\u8ba9\u6211\u4eec\u56de\u5230\u4f2a\u4ee3\u7801\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">promise.then(\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0futureValue\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\"><span class=\"comment\" style=\"color: #008200;\">\/*\u00a0we\u00a0got\u00a0a\u00a0value\u00a0*\/<\/span><\/li>\n<li style=\"color: #5c5c5c;\">}\u00a0,\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\"><span class=\"comment\" style=\"color: #008200;\">\/*\u00a0something\u00a0went\u00a0wrong\u00a0*\/<\/span><\/li>\n<li style=\"color: #5c5c5c;\">\u00a0}\u00a0);<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u83b7\u5f97\u591a\u4e2a\u8fd4\u56de\u7ed3\u679c\u540e\uff0c\u518d\u7ee7\u7eed\u6267\u884c\u5e94\u7528\u7a0b\u5e8f\uff08\u4f8b\u5982\uff0c\u5728\u7528\u6237\u53ef\u4ee5\u9009\u62e9\u4ed6\u4eec\u611f\u5174\u8da3\u7684\u9009\u9879\u524d\uff0c\u663e\u793a\u4e00\u7ec4\u52a8\u6001\u7684\u9009\u9879\uff09\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c&#8217;when&#8217;\u65b9\u6cd5\u53ef\u4ee5\u7528\u6765\u89e3\u51b3\u6240\u6709\u7684promise\u90fd\u6ee1\u8db3\u540e\u624d\u80fd\u7ee7\u7eed\u6267\u884c\u7684\u573a\u666f\u3002<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">when(<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0promise1,<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0promise2,<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0&#8230;<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0).then(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0futureValue1,\u00a0futureValue2,\u00a0&#8230;\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0<span class=\"comment\" style=\"color: #008200;\">\/*\u00a0all\u00a0promises\u00a0have\u00a0completed\u00a0and\u00a0are\u00a0resolved\u00a0*\/<\/span><\/li>\n<li style=\"color: #5c5c5c;\">\u00a0});<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u4e00\u4e2a\u5f88\u597d\u7684\u4f8b\u5b50\u662f\u8fd9\u6837\u4e00\u4e2a\u573a\u666f\uff0c\u4f60\u53ef\u80fd\u540c\u65f6\u6709\u591a\u4e2a\u6b63\u5728\u8fd0\u884c\u7684\u52a8\u753b\u3002 \u5982\u679c\u4e0d\u8ddf\u8e2a\u6bcf\u4e2a\u52a8\u753b\u6267\u884c\u5b8c\u6210\u540e\u7684\u56de\u8c03\uff0c\u5f88\u96be\u505a\u5230\u5728\u52a8\u753b\u5b8c\u6210\u540e\u6267\u884c\u4e0b\u4e00\u6b65\u4efb\u52a1\u3002\u7136\u800c\u4f7f\u7528promise\u548c\u2018when\u2019\u65b9\u5f0f\u5374\u53ef\u4ee5\u5f88\u76f4\u622a\u4e86\u5f53\u7684\u8868\u793a\uff1a \u4e00\u65e6\u52a8\u753b\u6267\u884c\u5b8c\u6210\uff0c\u5c31\u53ef\u4ee5\u6267\u884c\u4e0b\u4e00\u6b65\u4efb\u52a1\u3002\u6700\u7ec8\u7684\u7ed3\u679c\u662f\u6211\u4eec\u53ef\u4ee5\u53ef\u4ee5\u7b80\u5355\u7684\u7528\u4e00\u4e2a\u56de\u8c03\u6765\u89e3\u51b3\u591a\u4e2a\u52a8\u753b\u6267\u884c\u7ed3\u679c\u7684\u7b49\u5f85\u95ee\u9898\u3002 \u4f8b\u5982\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">when(\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(){<\/li>\n<li style=\"color: #5c5c5c;\"><span class=\"comment\" style=\"color: #008200;\">\/*\u00a0animation\u00a01\u00a0*\/<\/span><\/li>\n<li style=\"color: #5c5c5c;\"><span class=\"comment\" style=\"color: #008200;\">\/*\u00a0return\u00a0promise\u00a01\u00a0*\/<\/span><\/li>\n<li style=\"color: #5c5c5c;\">},\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(){<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0<span class=\"comment\" style=\"color: #008200;\">\/*\u00a0animation\u00a02\u00a0*\/<\/span><\/li>\n<li style=\"color: #5c5c5c;\"><span class=\"comment\" style=\"color: #008200;\">\/*\u00a0return\u00a0promise\u00a02\u00a0*\/<\/span><\/li>\n<li style=\"color: #5c5c5c;\">}\u00a0).then(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(){<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0<span class=\"comment\" style=\"color: #008200;\">\/*\u00a0once\u00a0both\u00a0animations\u00a0have\u00a0completed\u00a0we\u00a0can\u00a0then\u00a0run\u00a0our\u00a0additional\u00a0logic\u00a0*\/<\/span><\/li>\n<li style=\"color: #5c5c5c;\">});<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u8fd9\u610f\u5473\u7740\uff0c\u57fa\u672c\u4e0a\u53ef\u4ee5\u7528\u975e\u963b\u585e\u7684\u903b\u8f91\u65b9\u5f0f\u7f16\u5199\u4ee3\u7801\u5e76\u5f02\u6b65\u6267\u884c\u3002 \u800c\u4e0d\u662f\u76f4\u63a5\u5c06\u56de\u8c03\u4f20\u9012\u7ed9\u51fd\u6570\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7d27\u8026\u5408\u7684\u63a5\u53e3\uff0c\u901a\u8fc7promise\u6a21\u5f0f\u53ef\u4ee5\u5f88\u5bb9\u6613\u533a\u5206\u540c\u6b65\u548c\u5f02\u6b65\u7684\u6982\u5ff5\u3002<\/p>\n<p style=\"color: #393939;\">\u00a0\u3000\u3000\u5728\u4e0b\u4e00\u8282\u4e2d\uff0c\u6211\u4eec\u5c06\u7740\u773c\u4e8ejQuery\u5b9e\u73b0\u7684deferreds\uff0c\u4f60\u53ef\u80fd\u4f1a\u53d1\u73b0\u5b83\u660e\u663e\u6bd4\u73b0\u5728\u6240\u770b\u5230\u7684promise\u6a21\u5f0f\u8981\u7b80\u5355\u3002<\/p>\n<h4 style=\"font-weight: bold;\">jQuery\u7684Deferreds<\/h4>\n<p style=\"color: #393939;\">\u3000\u3000jQuery\u57281.5\u7248\u672c\u4e2d\u9996\u6b21\u5f15\u5165\u4e86deferreds\u3002\u5b83 \u6240\u5b9e\u73b0\u7684\u65b9\u6cd5\u4e0e\u6211\u4eec\u4e4b\u524d\u63cf\u8ff0\u7684\u62bd\u8c61\u7684\u6982\u5ff5\u6ca1\u6709\u5927\u7684\u5dee\u522b\u3002\u539f\u5219\u4e0a\uff0c\u4f60\u83b7\u5f97\u4e86\u5728\u672a\u6765\u67d0\u4e2a\u65f6\u5019\u5f97\u5230\u2018\u5ef6\u65f6\u2019\u8fd4\u56de\u503c\u7684\u80fd\u529b\u3002\u5728\u6b64\u4e4b\u524d\u662f\u65e0\u6cd5\u5355\u72ec\u4f7f\u7528\u7684\u3002 Deferreds \u4f5c\u4e3a\u5bf9ajax\u6a21\u5757\u8f83\u5927\u91cd\u5199\u7684\u4e00\u90e8\u5206\u6dfb\u52a0\u8fdb\u6765\uff0c\u5b83\u9075\u5faa\u4e86CommonJS\u7684promise\/ A\u8bbe\u8ba1\u30021.5\u548c\u5148\u524d\u7684\u7248\u672c\u5305\u542bdeferred\u529f\u80fd\uff0c\u53ef\u4ee5\u4f7f$.ajax() \u63a5\u6536\u8c03\u7528\u5b8c\u6210\u53ca\u8bf7\u6c42\u51fa\u9519\u7684\u56de\u8c03\uff0c\u4f46\u5374\u5b58\u5728\u4e25\u91cd\u7684\u8026\u5408\u3002\u5f00\u53d1\u4eba\u5458\u901a\u5e38\u4f1a\u4f7f\u7528\u5176\u4ed6\u5e93\u6216\u5de5\u5177\u5305\u6765\u5904\u7406\u5ef6\u8fdf\u4efb\u52a1\u3002\u65b0\u7248\u672c\u7684jQuery\u63d0\u4f9b\u4e86\u4e00\u4e9b\u589e\u5f3a\u7684\u65b9\u5f0f\u6765\u7ba1\u7406 \u56de\u8c03\uff0c\u63d0\u4f9b\u66f4\u52a0\u7075\u6d3b\u7684\u65b9\u5f0f\u5efa\u7acb\u56de\u8c03\uff0c\u800c\u4e0d\u7528\u5173\u5fc3\u539f\u59cb\u7684\u56de\u8c03\u662f\u5426\u5df2\u7ecf\u89e6\u53d1\u3002 \u00a0\u540c\u65f6\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0cjQuery\u7684\u9012\u5ef6\u5bf9\u8c61\u652f\u6301\u591a\u4e2a\u56de\u8c03\u7ed1\u5b9a\u591a\u4e2a\u4efb\u52a1\uff0c\u4efb\u52a1\u672c\u8eab\u53ef\u4ee5\u65e2\u53ef\u4ee5\u662f\u540c\u6b65\u4e5f\u53ef\u4ee5\u662f\u5f02\u6b65\u7684\u3002<\/p>\n<p style=\"color: #393939;\">\u00a0\u3000\u3000\u60a8\u53ef\u4ee5\u6d4f\u89c8\u4e0b\u8868\u4e2d\u7684\u9012\u5ef6\u529f\u80fd\uff0c\u6709\u52a9\u4e8e\u4e86\u89e3\u54ea\u4e9b\u529f\u80fd\u662f\u4f60\u9700\u8981\u7684\uff1a<\/p>\n<p style=\"color: #393939;\">\n<div style=\"color: #393939;\">\n<table border=\"0\">\n<tbody>\n<tr>\n<td>jQuery.Deferred\uff08\uff09<\/td>\n<td>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Deferred\u5bf9\u8c61\u7684\u6784\u9020\u51fd\u6570\uff0c\u53ef\u4ee5\u5e26\u4e00\u4e2a\u53ef\u9009\u7684\u51fd\u6570\u53c2\u6570\uff0c\u5b83\u4f1a\u5728\u6784\u9020\u5b8c\u6210\u540e\u88ab\u8c03\u7528\u3002<\/td>\n<\/tr>\n<tr>\n<td>jQuery.when\uff08\uff09<\/td>\n<td>\u901a\u8fc7\u8be5\u65b9\u5f0f\u6765\u6267\u884c\u57fa\u4e8e\u4e00\u4e2a\u6216\u591a\u4e2a\u8868\u793a\u5f02\u6b65\u4efb\u52a1\u7684\u5bf9\u8c61\u4e0a\u7684\u56de\u8c03\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>jQuery.ajax\uff08\uff09<\/td>\n<td>\u6267\u884c\u5f02\u6b65Ajax\u8bf7\u6c42\uff0c\u8fd4\u56de\u5b9e\u73b0\u4e86promise\u63a5\u53e3\u7684jqXHR\u5bf9\u8c61<\/td>\n<\/tr>\n<tr>\n<td>deferred.then\uff08resolveCallback\uff0crejectCallback\uff09<\/td>\n<td>\u6dfb\u52a0\u5904\u7406\u7a0b\u5e8f\u88ab\u8c03\u7528\u65f6\uff0c\u9012\u5ef6\u5bf9\u8c61\u5f97\u5230\u89e3\u51b3\u6216\u8005\u62d2\u7edd\u7684\u56de\u8c03\u3002<\/td>\n<\/tr>\n<tr>\n<td>deferred.done\uff08\uff09<\/td>\n<td>\u5f53\u5ef6\u8fdf\u6210\u529f\u65f6\u8c03\u7528\u4e00\u4e2a\u51fd\u6570\u6216\u8005\u6570\u7ec4\u51fd\u6570.<\/td>\n<\/tr>\n<tr>\n<td>deferred.fail\uff08\uff09<\/td>\n<td>\u5f53\u5ef6\u8fdf\u5931\u8d25\u65f6\u8c03\u7528\u4e00\u4e2a\u51fd\u6570\u6216\u8005\u6570\u7ec4\u51fd\u6570.\u3002<\/td>\n<\/tr>\n<tr>\n<td>deferred.resolve\uff08ARG1\uff0cARG2\uff0c&#8230;\uff09<\/td>\n<td>\u8c03\u7528Deferred\u5bf9\u8c61\u6ce8\u518c\u7684\u2018done\u2019\u56de\u8c03\u51fd\u6570\u5e76\u4f20\u9012\u53c2\u6570<\/td>\n<\/tr>\n<tr>\n<td>deferred.resolveWith\uff08context\uff0cargs\uff09<\/td>\n<td>\u8c03\u7528Deferred\u5bf9\u8c61\u6ce8\u518c\u7684\u2018done\u2019\u56de\u8c03\u51fd\u6570\u5e76\u4f20\u9012\u53c2\u6570\u548c\u8bbe\u7f6e\u56de\u8c03\u4e0a\u4e0b\u6587<\/td>\n<\/tr>\n<tr>\n<td>deferred.isResolved<\/td>\n<td>\u786e\u5b9a\u4e00\u4e2aDeferred\u5bf9\u8c61\u662f\u5426\u5df2\u7ecf\u89e3\u51b3\u3002<\/td>\n<\/tr>\n<tr>\n<td>deferred.reject\uff08arg1\uff0carg2\uff0c&#8230;\uff09<\/td>\n<td>\u8c03\u7528Deferred\u5bf9\u8c61\u6ce8\u518c\u7684\u2018fail\u2019\u56de\u8c03\u51fd\u6570\u5e76\u4f20\u9012\u53c2\u6570<\/td>\n<\/tr>\n<tr>\n<td>deferred.rejectWith\uff08context\uff0cargs\uff09<\/td>\n<td>\u8c03\u7528Deferred\u5bf9\u8c61\u6ce8\u518c\u7684\u2018fail\u2019\u56de\u8c03\u51fd\u6570\u5e76\u4f20\u9012\u53c2\u6570\u548c\u8bbe\u7f6e\u56de\u8c03\u4e0a\u4e0b\u6587<\/td>\n<\/tr>\n<tr>\n<td>deferred.promise\uff08\uff09<\/td>\n<td>\u8fd4\u56depromise\u5bf9\u8c61\uff0c\u8fd9\u662f\u4e00\u4e2a\u4f2a\u9020\u7684deferred\u5bf9\u8c61\uff1a\u5b83\u57fa\u4e8edeferred\u5e76\u4e14\u4e0d\u80fd\u6539\u53d8\u72b6\u6001\u6240\u4ee5\u53ef\u4ee5\u88ab\u5b89\u5168\u7684\u4f20\u9012<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p style=\"color: #393939;\">\n<p style=\"color: #393939;\">\u3000\u3000jQuery\u5ef6\u65f6\u5b9e\u73b0\u7684\u6838\u5fc3\u662fjQuery.Deferred\uff1a\u4e00\u4e2a\u53ef\u4ee5\u94fe\u5f0f\u8c03\u7528\u7684\u6784\u9020\u51fd\u6570\u3002&#8230;&#8230; \u9700\u8981\u6ce8\u610f\u7684\u662f\u4efb\u4f55deferred\u5bf9\u8c61\u7684\u9ed8\u8ba4\u72b6\u6001\u662funresolved\uff0c \u56de\u8c03\u4f1a\u901a\u8fc7 .then() \u6216 .fail()\u65b9\u6cd5\u6dfb\u52a0\u5230\u961f\u5217\uff0c\u5e76\u5728\u7a0d\u540e\u7684\u8fc7\u7a0b\u4e2d\u88ab\u6267\u884c\u3002<\/p>\n<p style=\"color: #393939;\">\u3000\u3000\u4e0b\u9762\u8fd9\u4e2a$.when() \u63a5\u53d7\u591a\u4e2a\u53c2\u6570\u7684\u4f8b\u5b50<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\"><span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>\u00a0successFunc(){\u00a0console.log(\u00a0\u201csuccess!\u201d\u00a0);\u00a0}<\/li>\n<li style=\"color: #5c5c5c;\"><span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>\u00a0failureFunc(){\u00a0console.log(\u00a0\u201cfailure!\u201d\u00a0);\u00a0}<\/li>\n<li style=\"color: #5c5c5c;\"><\/li>\n<li style=\"color: #5c5c5c;\">$.when(<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0$.ajax(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;\/main.php&#8221;<\/span>\u00a0),<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0$.ajax(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;\/modules.php&#8221;<\/span>\u00a0),<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0$.ajax(\u00a0\u201c\/lists.php\u201d\u00a0)<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0).then(\u00a0successFunc,\u00a0failureFunc\u00a0);<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u5728$.when() \u7684\u5b9e\u73b0\u4e2d\u6709\u8da3\u7684\u662f\uff0c\u5b83\u5e76\u975e\u4ec5\u80fd\u89e3\u6790deferred\u5bf9\u8c61\uff0c\u8fd8\u53ef\u4ee5\u4f20\u9012\u4e0d\u662fdeferred\u5bf9\u8c61\u7684\u53c2\u6570\uff0c\u5728\u5904\u7406\u7684\u65f6\u5019\u4f1a\u628a\u5b83\u4eec\u5f53\u505adeferred\u5bf9\u8c61\u5e76\u7acb \u5373\u6267\u884c\u56de\u8c03\uff08doneCallbacks\uff09\u3002 \u8fd9\u4e5f\u662fjQuery\u7684Deferred\u5b9e\u73b0\u4e2d\u503c\u5f97\u4e00\u63d0\u7684\u5730\u65b9\uff0c\u6b64\u5916\uff0cdeferred.then\uff08\uff09\u8fd8\u4e3adeferred.done\u548c deferred.fail\uff08\uff09\u65b9\u6cd5\u5728deferred\u7684\u961f\u5217\u4e2d\u589e\u52a0\u56de\u8c03\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n<p style=\"color: #393939;\">\u3000\u3000\u5229\u7528\u524d\u9762\u4ecb\u7ecd\u7684\u8868\u4e2d\u63d0\u5230\u7684deferred\u529f\u80fd\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u4ee3\u7801\u793a\u4f8b\u3002 \u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u975e\u5e38\u57fa\u672c\u7684\u5e94\u7528\u7a0b\u5e8f\uff1a\u901a\u8fc7$.get\u65b9\u6cd5\uff08\u8fd4\u56de\u4e00\u4e2apromise\uff09\u83b7\u53d6\u4e00\u6761\u5916\u90e8\u65b0\u95fb\u6e90\uff081\uff09\u5e76\u4e14\uff082\uff09\u83b7\u53d6\u6700\u65b0\u7684\u4e00\u6761\u56de\u590d\u3002 \u00a0\u540c\u65f6\u7a0b\u5e8f\u8fd8\u901a\u8fc7\u51fd\u6570\uff08prepareInterface\uff08\uff09\uff09\u5b9e\u73b0\u65b0\u95fb\u548c\u56de\u590d\u5185\u5bb9\u663e\u793a\u5bb9\u5668\u7684\u52a8\u753b\u3002<\/p>\n<p style=\"color: #393939;\">\u3000\u3000\u4e3a\u4e86\u786e\u4fdd\u5728\u6267\u884c\u5176\u4ed6\u76f8\u5173\u884c\u4e3a\u524d\uff0c\u4e0a\u9762\u7684\u8fd9\u4e09\u4e2a\u6b65\u9aa4\u786e\u4fdd\u5b8c\u6210\uff0c\u6211\u4eec\u4f7f\u7528$.when()\u3002\u6839\u636e\u60a8\u7684\u9700\u8981 .then()\u548c.fail() \u5904\u7406\u51fd\u6570\u53ef\u4ee5\u88ab\u7528\u6765\u6267\u884c\u5176\u4ed6\u7a0b\u5e8f\u903b\u8f91\u3002<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\"><span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>\u00a0getLatestNews()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">return<\/span>\u00a0$.get(\u00a0\u201clatestNews.php\u201d,\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(data){<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0console.log(\u00a0\u201cnews\u00a0data\u00a0received\u201d\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0$(\u00a0\u201c.news\u201d\u00a0).html(data);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0}\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0}<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>\u00a0getLatestReactions()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">return<\/span>\u00a0$.get(\u00a0\u201clatestReactions.php\u201d,\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(data){<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(\u00a0\u201creactions\u00a0data\u00a0received\u201d\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$(\u00a0\u201c.reactions\u201d\u00a0).html(data);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0}\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0}<\/li>\n<li style=\"color: #5c5c5c;\"><\/li>\n<li style=\"color: #5c5c5c;\"><span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>\u00a0prepareInterface()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">return<\/span>\u00a0$.Deferred(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0dfd\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">var<\/span>\u00a0latest\u00a0=\u00a0$(\u00a0\u201c.news,\u00a0.reactions\u201d\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0latest.slideDown(\u00a0500,\u00a0dfd.resolve\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0latest.addClass(\u00a0\u201cactive\u201d\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0}).promise();<\/li>\n<li style=\"color: #5c5c5c;\">}<\/li>\n<li style=\"color: #5c5c5c;\"><\/li>\n<li style=\"color: #5c5c5c;\">$.when(<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0getLatestNews(),\u00a0getLatestReactions(),\u00a0prepareInterface()<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0).then(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(){<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0console.log(\u00a0\u201cfire\u00a0after\u00a0requests\u00a0succeed\u201d\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0}).fail(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(){<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0console.log(\u00a0\u201csomething\u00a0went\u00a0wrong!\u201d\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0});<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000deferreds\u5728ajax\u7684\u5e55\u540e\u64cd\u4f5c\u4e2d\u4f7f\u7528\u5e76\u4e0d\u610f\u5473\u7740\u5b83\u4eec\u65e0\u6cd5\u5728\u522b\u5904\u4f7f\u7528\u3002 \u5728\u672c\u8282\u4e2d\uff0c\u6211\u4eec\u5c06\u770b\u5230\u5728\u4e00\u4e9b\u89e3\u51b3\u65b9\u6848\u4e2d\uff0c\u4f7f\u7528deferreds\u5c06\u6709\u52a9\u4e8e\u62bd\u8c61\u6389\u5f02\u6b65\u7684\u884c\u4e3a\uff0c\u5e76\u89e3\u8026\u6211\u4eec\u7684\u4ee3\u7801\u3002<\/p>\n<h4 style=\"font-weight: bold;\"><strong>\u5f02\u6b65\u7f13\u5b58<\/strong><\/h4>\n<p style=\"color: #393939;\">\u3000\u3000\u5f53\u6d89\u53ca\u5230\u5f02\u6b65\u4efb\u52a1\uff0c\u7f13\u5b58\u53ef\u4ee5\u662f\u4e00\u4e2a\u6709\u70b9\u82db\u523b\u7684\uff0c\u56e0\u4e3a\u4f60\u5fc5\u987b\u786e\u4fdd\u5bf9\u4e8e\u540c\u4e00\u4e2akey\u4efb\u52a1\u4ec5\u6267\u884c\u4e00\u6b21\u3002\u56e0\u6b64\uff0c\u4ee3\u7801\u9700\u8981\u4ee5\u67d0\u79cd\u65b9\u5f0f\u8ddf\u8e2a\u5165\u7ad9\u4efb\u52a1\u3002 \u4f8b\u5982\u4e0b\u9762\u7684\u4ee3\u7801\u7247\u6bb5\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">$.cachedGetScript(\u00a0url,\u00a0callback1\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">$.cachedGetScript(\u00a0url,\u00a0callback2\u00a0);<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u7f13\u5b58\u673a\u5236\u9700\u8981\u786e\u4fdd \u811a\u672c\u4e0d\u7ba1\u662f\u5426\u5df2\u7ecf\u5b58\u5728\u4e8e\u7f13\u5b58\uff0c\u53ea\u80fd\u88ab\u8bf7\u6c42\u4e00\u6b21\u3002 \u56e0\u6b64\uff0c\u4e3a\u4e86\u7f13\u5b58\u7cfb\u7edf\u53ef\u4ee5\u6b63\u786e\u5730\u5904\u7406\u8bf7\u6c42,\u6211\u4eec\u6700\u7ec8\u9700\u8981\u5199\u51fa\u4e00\u4e9b\u903b\u8f91\u6765\u8ddf\u8e2a\u7ed1\u5b9a\u5230\u7ed9\u5b9aurl\u4e0a\u7684\u56de\u8c03\u3002<\/p>\n<p style=\"color: #393939;\">\u3000\u3000\u503c\u5f97\u5e86\u5e78\u7684\u662f\uff0c\u8fd9\u6070\u597d\u662fdeferred\u6240\u5b9e\u73b0\u7684\u90a3\u79cd\u903b\u8f91\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u8fd9\u6837\u6765\u505a\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\"><span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">var<\/span>\u00a0cachedScriptPromises\u00a0=\u00a0{};<\/li>\n<li style=\"color: #5c5c5c;\">$.cachedGetScript\u00a0=\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0url,\u00a0callback\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">if<\/span>\u00a0(\u00a0!cachedScriptPromises[\u00a0url\u00a0]\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0cachedScriptPromises[\u00a0url\u00a0]\u00a0=\u00a0$.Deferred(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0defer\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$.getScript(\u00a0url\u00a0).then(\u00a0defer.resolve,\u00a0defer.reject\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}).promise();<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0}<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">return<\/span>\u00a0cachedScriptPromises[\u00a0url\u00a0].done(\u00a0callback\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">};<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u4ee3\u7801\u76f8\u5f53\u7b80\u5355\uff1a\u6211\u4eec\u4e3a\u6bcf\u4e00\u4e2aurl\u7f13\u5b58\u4e00\u4e2apromise\u5bf9\u8c61\u3002 \u5982\u679c\u7ed9\u5b9a\u7684url\u6ca1\u6709promise\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2adeferred\uff0c\u5e76\u53d1\u51fa\u8bf7\u6c42\u3002 \u5982\u679c\u5b83\u5df2\u7ecf\u5b58\u5728\u6211\u4eec\u53ea\u9700\u8981\u4e3a\u5b83\u7ed1\u5b9a\u56de\u8c03\u3002 \u8be5\u89e3\u51b3\u65b9\u6848\u7684\u4e00\u5927\u4f18\u52bf\u662f\uff0c\u5b83\u4f1a\u900f\u660e\u5730\u5904\u7406\u65b0\u7684\u548c\u7f13\u5b58\u8fc7\u7684\u8bf7\u6c42\u3002 \u53e6\u4e00\u4e2a\u4f18\u70b9\u662f\u4e00\u4e2a\u57fa\u4e8edeferred\u7684\u7f13\u5b58 \u4f1a\u4f18\u96c5\u5730\u5904\u7406\u5931\u8d25\u60c5\u51b5\u3002 \u5f53promise\u4ee5\u2018rejected\u2019\u72b6\u6001\u7ed3\u675f\u7684\u8bdd\uff0c\u6211\u4eec\u53ef\u4ee5\u63d0\u4f9b\u4e00\u4e2a\u9519\u8bef\u56de\u8c03\u6765\u6d4b\u8bd5\uff1a<\/p>\n<p style=\"color: #393939;\">\u3000\u3000$.cachedGetScript( url ).then( successCallback, errorCallback );<\/p>\n<p style=\"color: #393939;\">\u3000\u3000\u8bf7\u8bb0\u4f4f\uff1a\u65e0\u8bba\u8bf7\u6c42\u662f\u5426\u7f13\u5b58\u8fc7\uff0c\u4e0a\u9762\u7684\u4ee3\u7801\u6bb5\u90fd\u4f1a\u6b63\u5e38\u8fd0\u4f5c\uff01<\/p>\n<h4 style=\"font-weight: bold;\">\u901a\u7528\u5f02\u6b65\u7f13\u5b58<\/h4>\n<p style=\"color: #393939;\">\u3000\u3000\u4e3a\u4e86\u4f7f\u4ee3\u7801\u5c3d\u53ef\u80fd\u7684\u901a\u7528\uff0c\u6211\u4eec\u5efa\u7acb\u4e00\u4e2a\u7f13\u5b58\u5de5\u5382\u5e76\u62bd\u8c61\u51fa\u5b9e\u9645\u9700\u8981\u6267\u884c\u7684\u4efb\u52a1\u200b\u200b\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">$.createCache\u00a0=\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0requestFunction\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">var<\/span>\u00a0cache\u00a0=\u00a0{};<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">return<\/span>\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0key,\u00a0callback\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">if<\/span>\u00a0(\u00a0!cache[\u00a0key\u00a0]\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0cache[\u00a0key\u00a0]\u00a0=\u00a0$.Deferred(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0defer\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0requestFunction(\u00a0defer,\u00a0key\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}).promise();<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">return<\/span>\u00a0cache[\u00a0key\u00a0].done(\u00a0callback\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0};<\/li>\n<li style=\"color: #5c5c5c;\">}<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u73b0\u5728\u5177\u4f53\u7684\u8bf7\u6c42\u903b\u8f91\u5df2\u7ecf\u62bd\u8c61\u51fa\u6765\uff0c\u6211\u4eec\u53ef\u4ee5\u91cd\u65b0\u5199cachedGetScript\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">$.cachedGetScript\u00a0=\u00a0$.createCache(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0defer,\u00a0url\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$.getScript(\u00a0url\u00a0).then(\u00a0defer.resolve,\u00a0defer.reject\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0});<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u00a0\u00a0\u6bcf\u6b21\u8c03\u7528createCache\u5c06\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7f13\u5b58\u5e93\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u9ad8\u901f\u7f13\u5b58\u68c0\u7d22\u51fd\u6570\u3002\u73b0\u5728\uff0c\u6211\u4eec\u62e5\u6709\u4e86\u4e00\u4e2a\u901a\u7528\u7684\u7f13\u5b58\u5de5\u5382\uff0c\u5b83\u5f88\u5bb9\u6613\u5b9e\u73b0\u6d89\u53ca\u4ece\u7f13\u5b58\u4e2d\u53d6\u503c\u7684\u903b\u8f91\u573a\u666f\u3002<\/p>\n<h4 style=\"font-weight: bold;\">\u56fe\u7247\u52a0\u8f7d<\/h4>\n<p style=\"color: #393939;\">\u3000\u3000\u53e6\u4e00\u4e2a\u5019\u9009\u573a\u666f\u662f\u56fe\u50cf\u52a0\u8f7d\uff1a\u786e\u4fdd\u6211\u4eec\u4e0d\u52a0\u8f7d\u540c\u4e00\u4e2a\u56fe\u50cf\u4e24\u6b21\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u52a0\u8f7d\u56fe\u50cf\u3002 \u4f7f\u7528createCache\u5f88\u5bb9\u6613\u5b9e\u73b0\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">$.loadImage\u00a0=\u00a0$.createCache(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0defer,\u00a0url\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">var<\/span>\u00a0image\u00a0=\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">new<\/span>\u00a0Image();<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>\u00a0cleanUp()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0image.onload\u00a0=\u00a0image.onerror\u00a0=\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">null<\/span>;<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0}<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0defer.then(\u00a0cleanUp,\u00a0cleanUp\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0image.onload\u00a0=\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0defer.resolve(\u00a0url\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0};<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0image.onerror\u00a0=\u00a0defer.reject;<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0image.src\u00a0=\u00a0url;<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0});<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u63a5\u4e0b\u6765\u7684\u4ee3\u7801\u7247\u6bb5\u5982\u4e0b\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">$.loadImage(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;my-image.png&#8221;<\/span>\u00a0).done(\u00a0callback1\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">$.loadImage(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;my-image.png&#8221;<\/span>\u00a0).done(\u00a0callback2\u00a0);<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u65e0\u8bbaimage.png\u662f\u5426\u5df2\u7ecf\u88ab\u52a0\u8f7d\uff0c\u6216\u8005\u6b63\u5728\u52a0\u8f7d\u8fc7\u7a0b\u4e2d\uff0c\u7f13\u5b58\u90fd\u4f1a\u6b63\u5e38\u5de5\u4f5c\u3002<\/p>\n<h4 style=\"font-weight: bold;\">\u7f13\u5b58\u6570\u636e\u7684API\u54cd\u5e94<\/h4>\n<p style=\"color: #393939;\">\u3000\u3000\u54ea\u4e9b\u4f60\u7684\u9875\u9762\u7684\u751f\u547d\u5468\u671f\u8fc7\u7a0b\u4e2d\u88ab\u8ba4\u4e3a\u662f\u4e0d\u53ef\u53d8\u7684API\u8bf7\u6c42\uff0c\u4e5f\u662f\u7f13\u5b58\u5b8c\u7f8e\u7684\u5019\u9009\u573a\u666f\u3002 \u6bd4\u5982\uff0c\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">$.searchTwitter\u00a0=\u00a0$.createCache(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0defer,\u00a0query\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0$.ajax({<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0url:\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;http:\/\/search.twitter.com\/search.json&#8221;<\/span>,<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0data:\u00a0{\u00a0q:\u00a0query\u00a0},<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0dataType:\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;jsonp&#8221;<\/span>,<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0success:\u00a0defer.resolve,<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0error:\u00a0defer.reject<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0});<\/li>\n<li style=\"color: #5c5c5c;\">});<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u7a0b\u5e8f\u5141\u8bb8\u4f60\u5728Twitter\u4e0a\u8fdb\u884c\u641c\u7d22\uff0c\u540c\u65f6\u7f13\u5b58\u5b83\u4eec\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">$.searchTwitter(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;jQuery\u00a0Deferred&#8221;<\/span>,\u00a0callback1\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">$.searchTwitter(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;jQuery\u00a0Deferred&#8221;<\/span>,\u00a0callback2\u00a0);<\/li>\n<\/ol>\n<\/div>\n<h4 style=\"font-weight: bold;\">\u5b9a\u65f6<\/h4>\n<p style=\"color: #393939;\">\u3000\u3000\u57fa\u4e8edeferred\u7684\u7f13\u5b58\u5e76\u4e0d\u9650\u5b9a\u4e8e\u7f51\u7edc\u8bf7\u6c42;\u5b83\u4e5f\u53ef\u4ee5\u88ab\u7528\u4e8e\u5b9a\u65f6\u76ee\u7684\u3002<\/p>\n<p style=\"color: #393939;\">\u3000\u3000\u4f8b\u5982\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5728\u7f51\u9875\u4e0a\u7ed9\u5b9a\u4e00\u6bb5\u65f6\u95f4\u540e\u6267\u884c\u4e00\u4e2a\u52a8\u4f5c\uff0c\u6765\u5438\u5f15\u7528\u6237\u5bf9\u67d0\u4e2a\u4e0d\u5bb9\u6613\u5f15\u8d77\u6ce8\u610f\u7684\u7279\u5b9a\u529f\u80fd\u7684\u5173\u6ce8\u6216\u5904\u7406\u4e00\u4e2a\u5ef6\u65f6\u95ee\u9898\u3002 \u867d\u7136setTimeout\u9002\u5408\u5927\u591a\u6570\u7528\u4f8b\uff0c\u4f46\u5728\u8ba1\u65f6\u5668\u51fa\u53d1\u540e\u751a\u81f3\u7406\u8bba\u4e0a\u8fc7\u671f\u540e\u5c31\u65e0\u6cd5\u63d0\u4f9b\u89e3\u51b3\u529e\u6cd5\u3002 \u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7684\u7f13\u5b58\u7cfb\u7edf\u6765\u5904\u7406\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\"><span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">var<\/span>\u00a0readyTime;<\/li>\n<li style=\"color: #5c5c5c;\">$(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{\u00a0readyTime\u00a0=\u00a0jQuery.now();\u00a0});<\/li>\n<li style=\"color: #5c5c5c;\">$.afterDOMReady\u00a0=\u00a0$.createCache(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0defer,\u00a0delay\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0delay\u00a0=\u00a0delay\u00a0||\u00a00;<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0$(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">var<\/span>\u00a0delta\u00a0=\u00a0$.now()\u00a0&#8211;\u00a0readyTime;<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">if<\/span>\u00a0(\u00a0delta\u00a0&gt;=\u00a0delay\u00a0)\u00a0{\u00a0defer.resolve();\u00a0}<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">else<\/span>\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setTimeout(\u00a0defer.resolve,\u00a0delay\u00a0&#8211;\u00a0delta\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0});<\/li>\n<li style=\"color: #5c5c5c;\">});<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u65b0\u7684afterDOMReady\u8f85\u52a9\u65b9\u6cd5\u7528\u6700\u5c11\u7684\u8ba1\u6570\u5668\u63d0\u4f9b\u4e86domReady\u540e\u7684\u9002\u5f53\u65f6\u673a\u3002 \u5982\u679c\u5ef6\u8fdf\u5df2\u7ecf\u8fc7\u671f\uff0c\u56de\u8c03\u4f1a\u88ab\u9a6c\u4e0a\u6267\u884c\u3002<\/p>\n<h4 style=\"font-weight: bold;\">\u540c\u6b65\u591a\u4e2a\u52a8\u753b<\/h4>\n<p style=\"color: #393939;\">\u3000\u3000\u52a8\u753b\u662f\u53e6\u4e00\u4e2a\u5e38\u89c1\u7684\u5f02\u6b65\u4efb\u52a1\u8303\u4f8b\u3002 \u7136\u800c\u5728\u51e0\u4e2a\u4e0d\u76f8\u5173\u7684\u52a8\u753b\u5b8c\u6210\u540e\u6267\u884c\u4ee3\u7801\u4ecd\u7136\u6709\u70b9\u6311\u6218\u6027\u3002\u5c3d\u7ba1\u5728jQuery1.6\u4e2d\u624d\u63d0\u4f9b\u4e86\u5728\u52a8\u753b\u5143\u7d20\u4e0a\u53d6\u5f97promise\u5bf9\u8c61\u7684\u529f\u80fd\uff0c\u4f46\u5b83\u662f\u5f88\u5bb9\u6613\u7684\u624b\u52a8\u5b9e\u73b0\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">$.fn.animatePromise\u00a0=\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0prop,\u00a0speed,\u00a0easing,\u00a0callback\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">var<\/span>\u00a0elements\u00a0=\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">this<\/span>;<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">return<\/span>\u00a0$.Deferred(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0defer\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0elements.animate(\u00a0prop,\u00a0speed,\u00a0easing,\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0defer.resolve();<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">if<\/span>\u00a0(\u00a0callback\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0callback.apply(\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">this<\/span>,\u00a0arguments\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0}).promise();<\/li>\n<li style=\"color: #5c5c5c;\">};<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u00a0\u3000\u3000\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528$.when()\u540c\u6b65\u5316\u4e0d\u540c\u7684\u52a8\u753b\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\"><span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">var<\/span>\u00a0fadeDiv1Out\u00a0=\u00a0$(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;#div1&#8221;<\/span>\u00a0).animatePromise({\u00a0opacity:\u00a00\u00a0}),<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0fadeDiv2In\u00a0=\u00a0$(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;#div1&#8221;<\/span>\u00a0).animatePromise({\u00a0opacity:\u00a01\u00a0},\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;fast&#8221;<\/span>\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\"><\/li>\n<li style=\"color: #5c5c5c;\">$.when(\u00a0fadeDiv1Out,\u00a0fadeDiv2In\u00a0).done(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"comment\" style=\"color: #008200;\">\/*\u00a0both\u00a0animations\u00a0ended\u00a0*\/<\/span><\/li>\n<li style=\"color: #5c5c5c;\">\u00a0});<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528\u540c\u6837\u7684\u6280\u5de7\uff0c\u5efa\u7acb\u4e86\u4e00\u4e9b\u8f85\u52a9\u65b9\u6cd5\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">$.each([\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;slideDown&#8221;<\/span>,\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;slideUp&#8221;<\/span>,\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;slideToggle&#8221;<\/span>,\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;fadeIn&#8221;<\/span>,\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;fadeOut&#8221;<\/span>,\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;fadeToggle&#8221;<\/span>\u00a0],<\/li>\n<li style=\"color: #5c5c5c;\"><span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0_,\u00a0name\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0$.fn[\u00a0name\u00a0+\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;Promise&#8221;<\/span>\u00a0]\u00a0=\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0speed,\u00a0easing,\u00a0callback\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">var<\/span>\u00a0elements\u00a0=\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">this<\/span>;<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">return<\/span>\u00a0$.Deferred(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0defer\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0elements[\u00a0name\u00a0](\u00a0speed,\u00a0easing,\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0defer.resolve();<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">if<\/span>\u00a0(\u00a0callback\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0callback.apply(\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">this<\/span>,\u00a0arguments\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}).promise();<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0};<\/li>\n<li style=\"color: #5c5c5c;\">});<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u7136\u540e\u60f3\u4e0b\u9762\u8fd9\u6837\u4f7f\u7528\u65b0\u7684\u52a9\u624b\u4ee3\u7801\u6765\u540c\u6b65\u52a8\u753b\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">$.when(<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0$(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;#div1&#8221;<\/span>\u00a0).fadeOutPromise(),<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0$(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;#div2&#8221;<\/span>\u00a0).fadeInPromise(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;fast&#8221;<\/span>\u00a0)<\/li>\n<li style=\"color: #5c5c5c;\">).done(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0<span class=\"comment\" style=\"color: #008200;\">\/*\u00a0both\u00a0animations\u00a0are\u00a0done\u00a0*\/<\/span><\/li>\n<li style=\"color: #5c5c5c;\">\u00a0});<\/li>\n<li style=\"color: #5c5c5c;\"><\/li>\n<\/ol>\n<\/div>\n<h4 style=\"font-weight: bold;\">\u4e00\u6b21\u6027\u4e8b\u4ef6<\/h4>\n<p style=\"color: #393939;\">\u3000\u3000\u867d\u7136jQuery\u63d0\u4f9b\u4f60\u53ef\u80fd\u9700\u8981\u7684\u6240\u6709\u7684\u65f6\u95f4\u7ed1\u5b9a\u65b9\u6cd5\uff0c\u4f46\u5f53\u4e8b\u4ef6\u4ec5\u9700\u8981\u5904\u7406\u4e00\u6b21\u65f6\uff0c\u60c5\u51b5\u53ef\u80fd\u4f1a\u53d8\u5f97\u6709\u70b9\u68d8\u624b\u3002\uff08 \u4e0e$.one() \u4e0d\u540c )<\/p>\n<p style=\"color: #393939;\">\u3000\u3000\u4f8b\u5982\uff0c\u60a8\u53ef\u80fd\u5e0c\u671b\u6709\u4e00\u4e2a\u6309\u94ae\uff0c\u5f53\u5b83\u7b2c\u4e00\u6b21\u88ab\u70b9\u51fb\u65f6\u6253\u5f00\u4e00\u4e2a\u9762\u677f\uff0c\u9762\u677f\u6253\u5f00\u4e4b\u540e\uff0c\u6267\u884c\u7279\u5b9a\u7684\u521d\u59cb\u5316\u903b\u8f91\u3002 \u5728\u5904\u7406\u8fd9\u79cd\u60c5\u51b5\u65f6\uff0c\u4eba\u4eec\u901a\u5e38\u4f1a\u8fd9\u6837\u5199\u4ee3\u7801\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\"><span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">var<\/span>\u00a0buttonClicked\u00a0=\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">false<\/span>;<\/li>\n<li style=\"color: #5c5c5c;\">$(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;#myButton&#8221;<\/span>\u00a0).click(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">if<\/span>\u00a0(\u00a0!buttonClicked\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0buttonClicked\u00a0=\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">true<\/span>;<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0initializeData();<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0showPanel();<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0}<\/li>\n<li style=\"color: #5c5c5c;\">});<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u4e0d\u4e45\u540e\uff0c\u4f60\u53ef\u80fd\u4f1a\u5728\u9762\u677f\u6253\u5f00\u4e4b\u540e\u70b9\u51fb\u6309\u94ae\u65f6\u6dfb\u52a0\u4e00\u4e9b\u64cd\u4f5c\uff0c\u5982\u4e0b\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\"><span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">if<\/span>\u00a0(\u00a0buttonClicked\u00a0)\u00a0{\u00a0<span class=\"comment\" style=\"color: #008200;\">\/*\u00a0perform\u00a0specific\u00a0action\u00a0*\/<\/span>\u00a0}<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u8026\u5408\u7684\u89e3\u51b3\u529e\u6cd5\u3002 \u5982\u679c\u4f60\u60f3\u6dfb\u52a0\u4e00\u4e9b\u5176\u4ed6\u7684\u64cd\u4f5c\uff0c\u4f60\u5fc5\u987b\u7f16\u8f91\u7ed1\u5b9a\u4ee3\u7801\u6216\u62f7\u8d1d\u4e00\u4efd\u3002 \u5982\u679c\u4f60\u4e0d\u8fd9\u6837\u505a\uff0c\u4f60\u552f\u4e00\u7684\u9009\u62e9\u662f\u6d4b\u8bd5buttonClicked\u3002\u7531\u4e8ebuttonClicked\u53ef\u80fd\u662ffalse\uff0c\u65b0\u7684\u4ee3\u7801\u53ef\u80fd\u6c38\u8fdc\u4e0d\u4f1a\u88ab\u6267\u884c\uff0c\u56e0\u6b64\u4f60 \u53ef\u80fd\u4f1a\u5931\u53bb\u8fd9\u4e2a\u65b0\u7684\u52a8\u4f5c\u3002<\/p>\n<p style=\"color: #393939;\">\u3000\u3000\u4f7f\u7528deferreds\u6211\u4eec\u53ef\u4ee5\u505a\u7684\u66f4\u597d \uff08\u4e3a\u7b80\u5316\u8d77\u89c1\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u5c06\u53ea\u9002\u7528\u4e8e\u4e00\u4e2a\u5355\u4e00\u7684\u5143\u7d20\u548c\u4e00\u4e2a\u5355\u4e00\u7684\u4e8b\u4ef6\u7c7b\u578b\uff0c\u4f46\u5b83\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u6269\u5c55\u4e3a\u591a\u4e2a\u4e8b\u4ef6\u7c7b\u578b\u7684\u96c6\u5408\uff09\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">$.fn.bindOnce\u00a0=\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0event,\u00a0callback\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">var<\/span>\u00a0element\u00a0=\u00a0$(\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">this<\/span>[\u00a00\u00a0]\u00a0),<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0defer\u00a0=\u00a0element.data(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;bind_once_defer_&#8221;<\/span>\u00a0+\u00a0event\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">if<\/span>\u00a0(\u00a0!defer\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0defer\u00a0=\u00a0$.Deferred();<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>\u00a0deferCallback()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0element.unbind(\u00a0event,\u00a0deferCallback\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0defer.resolveWith(\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">this<\/span>,\u00a0arguments\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0element.bind(\u00a0event,\u00a0deferCallback\u00a0)<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0element.data(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;bind_once_defer_&#8221;<\/span>\u00a0+\u00a0event\u00a0,\u00a0defer\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0}<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">return<\/span>\u00a0defer.done(\u00a0callback\u00a0).promise();<\/li>\n<li style=\"color: #5c5c5c;\">};<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u8be5\u4ee3\u7801\u7684\u5de5\u4f5c\u539f\u7406\u5982\u4e0b\uff1a<\/p>\n<ul style=\"color: #393939;\">\n<li>\u68c0\u67e5\u8be5\u5143\u7d20\u662f\u5426\u5df2\u7ecf\u7ed1\u5b9a\u4e86\u4e00\u4e2a\u7ed9\u5b9a\u4e8b\u4ef6\u7684deferred\u5bf9\u8c61<\/li>\n<li>\u5982\u679c\u6ca1\u6709\uff0c\u521b\u5efa\u5b83\uff0c\u4f7f\u5b83\u5728\u89e6\u53d1\u8be5\u4e8b\u4ef6\u7684\u7b2c\u4e00\u65f6\u95f4\u89e3\u51b3<\/li>\n<li>\u7136\u540e\u5728deferred\u4e0a\u7ed1\u5b9a\u7ed9\u5b9a\u7684\u56de\u8c03\u5e76\u8fd4\u56depromise<\/li>\n<\/ul>\n<p style=\"color: #393939;\">\u3000\u3000\u4ee3\u7801\u867d\u7136\u5f88\u5197\u957f\uff0c\u4f46\u5b83\u4f1a\u7b80\u5316\u76f8\u5173\u95ee\u9898\u7684\u5904\u7406\u3002 \u8ba9\u6211\u4eec\u5148\u5b9a\u4e49\u4e00\u4e2a\u8f85\u52a9\u65b9\u6cd5\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">$.fn.firstClick\u00a0=\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0callback\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">return<\/span>\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">this<\/span>.bindOnce(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;click&#8221;<\/span>,\u00a0callback\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0};<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u7136\u540e\uff0c\u4e4b\u524d\u7684\u903b\u8f91\u53ef\u4ee5\u91cd\u6784\u5982\u4e0b\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\"><span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">var<\/span>\u00a0openPanel\u00a0=\u00a0$(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;#myButton&#8221;<\/span>\u00a0).firstClick();<\/li>\n<li style=\"color: #5c5c5c;\">openPanel.done(\u00a0initializeData\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">openPanel.done(\u00a0showPanel\u00a0);<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u5982\u679c\u6211\u4eec\u9700\u8981\u6267\u884c\u4e00\u4e9b\u52a8\u4f5c\uff0c\u53ea\u6709\u5f53\u9762\u677f\u6253\u5f00\u4ee5\u540e\uff0c\u6240\u6709\u6211\u4eec\u9700\u8981\u7684\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">openPanel.done(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{\u00a0<span class=\"comment\" style=\"color: #008200;\">\/*\u00a0perform\u00a0specific\u00a0action\u00a0*\/<\/span>\u00a0});<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u5982\u679c\u9762\u677f\u6ca1\u6709\u6253\u5f00\uff0c\u884c\u52a8\u5c06\u5f97\u5230\u5ef6\u8fdf\u5230\u5355\u51fb\u8be5\u6309\u94ae\u65f6\u3002<\/p>\n<h4 style=\"font-weight: bold;\"><strong>\u7ec4\u5408\u52a9\u624b<\/strong><\/h4>\n<p style=\"color: #393939;\">\u3000\u3000\u5355\u72ec\u770b\u4ee5\u4e0a\u6bcf\u4e2a\u4f8b\u5b50\uff0cpromise\u7684\u4f5c\u7528\u662f\u6709\u9650\u7684 \u3002 \u7136\u800c\uff0cpromise\u771f\u6b63\u7684\u529b\u91cf\u662f\u628a\u5b83\u4eec\u6df7\u5408\u5728\u4e00\u8d77\u3002<\/p>\n<p style=\"color: #393939;\">\n<p style=\"color: #393939;\"><strong>\u5728\u7b2c\u4e00\u6b21\u70b9\u51fb\u65f6\u52a0\u8f7d\u9762\u677f\u5185\u5bb9\u5e76\u6253\u5f00\u9762\u677f<\/strong><\/p>\n<p style=\"color: #393939;\">\u3000\u3000\u5047\u5982\uff0c\u6211\u4eec\u6709\u4e00\u4e2a\u6309\u94ae\uff0c\u53ef\u4ee5\u6253\u5f00\u4e00\u4e2a\u9762\u677f\uff0c\u8bf7\u6c42\u5176\u5185\u5bb9\u7136\u540e\u6de1\u5165\u5185\u5bb9\u3002\u4f7f\u7528\u6211\u4eec\u524d\u9762\u5b9a\u4e49\u7684\u52a9\u624b\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u8fd9\u6837\u505a\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\"><span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">var<\/span>\u00a0panel\u00a0=\u00a0$(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;#myPanel&#8221;<\/span>\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">panel.firstClick(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0$.when(<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$.get(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;panel.html&#8221;<\/span>\u00a0),<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0panel.slideDownPromise()<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0).done(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>(\u00a0ajaxResponse\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0panel.html(\u00a0ajaxResponse[\u00a00\u00a0]\u00a0).fadeIn();<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0});<\/li>\n<li style=\"color: #5c5c5c;\">});<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\"><strong>\u5728\u7b2c\u4e00\u6b21\u70b9\u51fb\u65f6\u8f7d\u5165\u56fe\u50cf\u5e76\u6253\u5f00\u9762\u677f<\/strong><\/p>\n<p style=\"color: #393939;\">\u3000\u3000\u5047\u5982\uff0c\u6211\u4eec\u5df2\u7ecf\u7684\u9762\u677f\u6709\u5185\u5bb9\uff0c\u4f46\u6211\u4eec\u53ea\u5e0c\u671b\u5f53\u7b2c\u4e00\u6b21\u5355\u51fb\u6309\u94ae\u65f6\u52a0\u8f7d\u56fe\u50cf\u5e76\u4e14\u5f53\u6240\u6709\u56fe\u50cf\u52a0\u8f7d\u6210\u529f\u540e\u6de1\u5165\u56fe\u50cf\u3002HTML\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-xml\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\"><span class=\"tag\" style=\"color: #000000;\">&lt;<\/span><span class=\"tag-name\" style=\"color: #000000;\">div<\/span>\u00a0<span class=\"attribute\" style=\"color: #000000;\">id<\/span>=<span class=\"attribute-value\" style=\"color: #000000;\">&#8220;myPanel&#8221;<\/span><span class=\"tag\" style=\"color: #000000;\">&gt;<\/span><\/li>\n<li style=\"color: #5c5c5c;\"><span class=\"tag\" style=\"color: #000000;\">&lt;<\/span><span class=\"tag-name\" style=\"color: #000000;\">img<\/span>\u00a0<span class=\"attribute\" style=\"color: #000000;\">data-src<\/span>=<span class=\"attribute-value\" style=\"color: #000000;\">&#8220;image1.png&#8221;<\/span>\u00a0<span class=\"tag\" style=\"color: #000000;\">\/&gt;<\/span><\/li>\n<li style=\"color: #5c5c5c;\">\u00a0<span class=\"tag\" style=\"color: #000000;\">&lt;<\/span><span class=\"tag-name\" style=\"color: #000000;\">img<\/span>\u00a0<span class=\"attribute\" style=\"color: #000000;\">data-src<\/span>=<span class=\"attribute-value\" style=\"color: #000000;\">&#8220;image2.png&#8221;<\/span>\u00a0<span class=\"tag\" style=\"color: #000000;\">\/&gt;<\/span><\/li>\n<li style=\"color: #5c5c5c;\">\u00a0<span class=\"tag\" style=\"color: #000000;\">&lt;<\/span><span class=\"tag-name\" style=\"color: #000000;\">img<\/span>\u00a0<span class=\"attribute\" style=\"color: #000000;\">data-src<\/span>=<span class=\"attribute-value\" style=\"color: #000000;\">&#8220;image3.png&#8221;<\/span>\u00a0<span class=\"tag\" style=\"color: #000000;\">\/&gt;<\/span><\/li>\n<li style=\"color: #5c5c5c;\"><span class=\"tag\" style=\"color: #000000;\">&lt;<\/span><span class=\"tag-name\" style=\"color: #000000;\">img<\/span>\u00a0<span class=\"attribute\" style=\"color: #000000;\">data-src<\/span>=<span class=\"attribute-value\" style=\"color: #000000;\">&#8220;image4.png&#8221;<\/span>\u00a0<span class=\"tag\" style=\"color: #000000;\">\/&gt;<\/span><\/li>\n<li style=\"color: #5c5c5c;\"><span class=\"tag\" style=\"color: #000000;\">&lt;\/<\/span><span class=\"tag-name\" style=\"color: #000000;\">div<\/span><span class=\"tag\" style=\"color: #000000;\">&gt;<\/span><\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u6211\u4eec\u4f7f\u7528data-src\u5c5e\u6027\u63cf\u8ff0\u56fe\u7247\u7684\u771f\u5b9e\u8def\u5f84\u3002 \u90a3\u4e48\u4f7f\u7528promise\u52a9\u624b\u6765\u89e3\u51b3\u8be5\u7528\u4f8b\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">$(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;#myButton&#8221;<\/span>\u00a0).firstClick(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">var<\/span>\u00a0panel\u00a0=\u00a0$(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;#myPanel&#8221;<\/span>\u00a0),<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0promises\u00a0=\u00a0[];<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0$(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;img&#8221;<\/span>,\u00a0panel\u00a0).each(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">var<\/span>\u00a0image\u00a0=\u00a0$(\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">this<\/span>\u00a0),\u00a0src\u00a0=\u00a0element.attr(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;data-src&#8221;<\/span>\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">if<\/span>\u00a0(\u00a0src\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0promises.push(<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$.loadImage(\u00a0src\u00a0).then(\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0image.attr(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;src&#8221;<\/span>,\u00a0src\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0image.attr(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;src&#8221;<\/span>,\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;error.png&#8221;<\/span>\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\u00a0)<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0});<\/li>\n<li style=\"color: #5c5c5c;\"><\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0promises.push(\u00a0panel.slideDownPromise()\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\"><\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0$.when.apply(\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">null<\/span>,\u00a0promises\u00a0).done(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{\u00a0panel.fadeIn();\u00a0});<\/li>\n<li style=\"color: #5c5c5c;\">});<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u8fd9\u91cc\u7684\u7a8d\u95e8\u662f\u8ddf\u8e2a\u6240\u6709\u7684LoadImage \u7684promise\uff0c\u63a5\u4e0b\u6765\u52a0\u5165\u9762\u677fslideDown\u52a8\u753b\u3002 \u56e0\u6b64\u9996\u6b21\u70b9\u51fb\u6309\u94ae\u65f6\uff0c\u9762\u677f\u5c06slideDown\u5e76\u4e14\u56fe\u50cf\u5c06\u5f00\u59cb\u52a0\u8f7d\u3002 \u4e00\u65e6\u5b8c\u6210\u5411\u4e0b\u6ed1\u52a8\u9762\u677f\u548c\u5df2\u52a0\u8f7d\u7684\u6240\u6709\u56fe\u50cf\uff0c\u9762\u677f\u624d\u4f1a\u6de1\u5165\u3002<\/p>\n<h4 style=\"font-weight: bold;\">\u5728\u7279\u5b9a\u5ef6\u65f6\u540e\u52a0\u8f7d\u9875\u9762\u4e0a\u7684\u56fe\u50cf<\/h4>\n<p style=\"color: #393939;\">\u3000\u3000\u5047\u5982\uff0c\u6211\u4eec\u8981\u5728\u6574\u4e2a\u9875\u9762\u5b9e\u73b0\u9012\u5ef6\u56fe\u50cf\u663e\u793a\u3002 \u8981\u505a\u5230\u8fd9\u4e00\u70b9\uff0c\u6211\u4eec\u9700\u8981\u7684HTML\u7684\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-xml\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\"><span class=\"tag\" style=\"color: #000000;\">&lt;<\/span><span class=\"tag-name\" style=\"color: #000000;\">img<\/span>\u00a0<span class=\"attribute\" style=\"color: #000000;\">data-src<\/span>=<span class=\"attribute-value\" style=\"color: #000000;\">&#8220;image1.png&#8221;<\/span>\u00a0<span class=\"attribute\" style=\"color: #000000;\">data-after<\/span>=<span class=\"attribute-value\" style=\"color: #000000;\">&#8220;1000&#8221;<\/span>\u00a0<span class=\"attribute\" style=\"color: #000000;\">src<\/span>=<span class=\"attribute-value\" style=\"color: #000000;\">&#8220;placeholder.png&#8221;<\/span>\u00a0<span class=\"tag\" style=\"color: #000000;\">\/&gt;<\/span><\/li>\n<li style=\"color: #5c5c5c;\"><span class=\"tag\" style=\"color: #000000;\">&lt;<\/span><span class=\"tag-name\" style=\"color: #000000;\">img<\/span>\u00a0<span class=\"attribute\" style=\"color: #000000;\">data-src<\/span>=<span class=\"attribute-value\" style=\"color: #000000;\">&#8220;image2.png&#8221;<\/span>\u00a0<span class=\"attribute\" style=\"color: #000000;\">data-after<\/span>=<span class=\"attribute-value\" style=\"color: #000000;\">&#8220;1000&#8221;<\/span>\u00a0<span class=\"attribute\" style=\"color: #000000;\">src<\/span>=<span class=\"attribute-value\" style=\"color: #000000;\">&#8220;placeholder.png&#8221;<\/span>\u00a0<span class=\"tag\" style=\"color: #000000;\">\/&gt;<\/span><\/li>\n<li style=\"color: #5c5c5c;\"><span class=\"tag\" style=\"color: #000000;\">&lt;<\/span><span class=\"tag-name\" style=\"color: #000000;\">img<\/span>\u00a0<span class=\"attribute\" style=\"color: #000000;\">data-src<\/span>=<span class=\"attribute-value\" style=\"color: #000000;\">&#8220;image1.png&#8221;<\/span>\u00a0<span class=\"attribute\" style=\"color: #000000;\">src<\/span>=<span class=\"attribute-value\" style=\"color: #000000;\">&#8220;placeholder.png&#8221;<\/span>\u00a0<span class=\"tag\" style=\"color: #000000;\">\/&gt;<\/span><\/li>\n<li style=\"color: #5c5c5c;\"><span class=\"tag\" style=\"color: #000000;\">&lt;<\/span><span class=\"tag-name\" style=\"color: #000000;\">img<\/span>\u00a0<span class=\"attribute\" style=\"color: #000000;\">data-src<\/span>=<span class=\"attribute-value\" style=\"color: #000000;\">&#8220;image2.png&#8221;<\/span>\u00a0<span class=\"attribute\" style=\"color: #000000;\">data-after<\/span>=<span class=\"attribute-value\" style=\"color: #000000;\">&#8220;2000&#8221;<\/span>\u00a0<span class=\"attribute\" style=\"color: #000000;\">src<\/span>=<span class=\"attribute-value\" style=\"color: #000000;\">&#8220;placeholder.png&#8221;<\/span>\u00a0<span class=\"tag\" style=\"color: #000000;\">\/&gt;<\/span><\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u610f\u601d\u975e\u5e38\u7b80\u5355\uff1a<\/p>\n<ul style=\"color: #393939;\">\n<li>image1.png\uff0c\u7b2c\u4e09\u4e2a\u56fe\u50cf\u7acb\u5373\u663e\u793a\uff0c\u4e00\u79d2\u540e\u7b2c\u4e00\u4e2a\u56fe\u50cf\u663e\u793a<\/li>\n<li>image2.png \u4e00\u79d2\u949f\u540e\u663e\u793a\u7b2c\u4e8c\u4e2a\u56fe\u50cf\uff0c\u4e24\u79d2\u949f\u540e\u663e\u793a\u7b2c\u56db\u4e2a\u56fe\u50cf<\/li>\n<\/ul>\n<p style=\"color: #393939;\">\u3000\u3000\u6211\u4eec\u5c06\u5982\u4f55\u5b9e\u73b0\u5462\uff1f<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">$(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;img&#8221;<\/span>\u00a0).each(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">var<\/span>\u00a0element\u00a0=\u00a0$(\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">this<\/span>\u00a0),<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0src\u00a0=\u00a0element.attr(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;data-src&#8221;<\/span>\u00a0),<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0after\u00a0=\u00a0element.attr(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;data-after&#8221;<\/span>\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">if<\/span>\u00a0(\u00a0src\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$.when(<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$.loadImage(\u00a0src\u00a0),<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$.afterDOMReady(\u00a0after\u00a0)<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0).then(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0element.attr(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;src&#8221;<\/span>,\u00a0src\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0element.attr(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;src&#8221;<\/span>,\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;error.png&#8221;<\/span>\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\u00a0).done(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0element.fadeIn();<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0}<\/li>\n<li style=\"color: #5c5c5c;\">});<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u00a0\u3000\u3000\u5982\u679c\u6211\u4eec\u60f3\u5ef6\u8fdf\u52a0\u8f7d\u7684\u56fe\u50cf\u672c\u8eab\uff0c\u4ee3\u7801\u4f1a\u6709\u6240\u4e0d\u540c\uff1a<\/p>\n<div id=\"\" class=\"dp-highlighter\" style=\"color: #393939;\">\n<ol class=\"dp-c\" style=\"color: #5c5c5c;\" start=\"1\">\n<li style=\"color: #5c5c5c;\">$(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;img&#8221;<\/span>\u00a0).each(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">var<\/span>\u00a0element\u00a0=\u00a0$(\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">this<\/span>\u00a0),<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0src\u00a0=\u00a0element.attr(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;data-src&#8221;<\/span>\u00a0),<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0after\u00a0=\u00a0element.attr(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;data-after&#8221;<\/span>\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">if<\/span>\u00a0(\u00a0src\u00a0)\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$.afterDOMReady(\u00a0after,\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$.loadImage(\u00a0src\u00a0).then(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0element.attr(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;src&#8221;<\/span>,\u00a0src\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},\u00a0<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0element.attr(\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;src&#8221;<\/span>,\u00a0<span class=\"string\" style=\"color: blue;\">&#8220;error.png&#8221;<\/span>\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\u00a0).done(<span class=\"keyword\" style=\"font-weight: bold; color: #006699;\">function<\/span>()\u00a0{<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0element.fadeIn();<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\u00a0);<\/li>\n<li style=\"color: #5c5c5c;\">\u00a0\u00a0\u00a0\u00a0}<\/li>\n<li style=\"color: #5c5c5c;\">});<\/li>\n<\/ol>\n<\/div>\n<p style=\"color: #393939;\">\u3000\u3000\u8fd9\u91cc\uff0c\u6211\u4eec\u9996\u5148\u5728\u5c1d\u8bd5\u52a0\u8f7d\u56fe\u7247\u4e4b\u524d\u7b49\u5f85\u5ef6\u8fdf\u6761\u4ef6\u6ee1\u8db3\u3002\u5f53\u4f60\u60f3\u5728\u9875\u9762\u52a0\u8f7d\u65f6\u9650\u5236\u7f51\u7edc\u8bf7\u6c42\u7684\u6570\u91cf\u4f1a\u975e\u5e38\u6709\u610f\u4e49\u3002<\/p>\n<h4 style=\"font-weight: bold;\">\u7ed3\u8bba<\/h4>\n<p style=\"color: #393939;\">\u3000\u3000\u6b63\u5982\u4f60\u770b\u5230\u7684\uff0c\u5373\u4f7f\u5728\u6ca1\u6709Ajax\u8bf7\u6c42\u7684\u60c5\u51b5\u4e0b\uff0cpromise\u4e5f\u975e\u5e38\u6709\u7528\u7684\u3002\u901a\u8fc7\u4f7f\u7528jQuery 1.5\u4e2d\u7684deferred\u5b9e\u73b0 \uff0c\u4f1a\u975e\u5e38\u5bb9\u6613\u7684\u4ece\u4f60\u7684\u4ee3\u7801\u4e2d\u5206\u79bb\u51fa\u5f02\u6b65\u4efb\u52a1\u3002 \u8fd9\u6837\u7684\u8bdd\uff0c\u4f60\u53ef\u4ee5\u5f88\u5bb9\u6613\u7684\u4ece\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5206\u79bb\u903b\u8f91\u3002<\/p>\n<p style=\"color: #393939;\"><a href=\"http:\/\/www.cnblogs.com\/lhb25\/archive\/2013\/03\/05\/jquery-deferred-promise.html\" target=\"_blank\">http:\/\/www.cnblogs.com\/lhb25\/archive\/2013\/03\/05\/jquery-deferred-promise.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\uff0c\u6211\u4eec\u4e00\u8d77\u63a2\u7d22\u4e00\u4e0b JavaScript \u4e2d\u7684 Deferred \u548c Promise \u7684\u6982\u5ff5\uff0c\u5b83\u4eec\u662f  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-4744","post","type-post","status-publish","format-standard","hentry","category-11"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/4744","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4744"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/4744\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}