{"id":233,"date":"2012-04-03T11:39:12","date_gmt":"2012-04-03T11:39:12","guid":{"rendered":"e165421110ba03099a1c0393373c5b43"},"modified":"2012-04-03T11:39:12","modified_gmt":"2012-04-03T11:39:12","slug":"","status":"publish","type":"post","link":"https:\/\/www.xiaobo.li\/notes\/archives\/233","title":{"rendered":"jquery array"},"content":{"rendered":"<p><strong>1. $.each(array, [callback]) \u904d\u5386<\/strong>[\u5e38\u7528]<br style=\"margin-bottom:7px;\" \/><br \/>\n<strong style=\"margin-right:3px;\">\u89e3\u91ca:&nbsp;<\/strong>\u4e0d\u540c\u4e8e\u4f8b\u904d jQuery \u5bf9\u8c61\u7684 $().each() \u65b9\u6cd5,\u6b64\u65b9\u6cd5\u53ef\u7528\u4e8e\u4f8b\u904d\u4efb\u4f55\u5bf9\u8c61(\u4e0d\u4ec5\u4ec5\u662f\u6570\u7ec4\u54e6~). \u56de\u8c03\u51fd\u6570\u62e5\u6709\u4e24\u4e2a\u53c2\u6570\uff1a\u7b2c\u4e00\u4e2a\u4e3a\u5bf9\u8c61\u7684\u6210\u5458\u6216\u6570\u7ec4\u7684\u7d22\u5f15, \u7b2c\u4e8c\u4e2a\u4e3a\u5bf9\u5e94\u53d8\u91cf\u6216\u5185\u5bb9. \u5982\u679c\u9700\u8981\u9000\u51fa each \u5faa\u73af\u53ef\u4f7f\u56de\u8c03\u51fd\u6570\u8fd4\u56de false, \u5176\u5b83\u8fd4\u56de\u503c\u5c06\u88ab\u5ffd\u7565.<br style=\"margin-bottom:7px;\" \/><br \/>\neach\u904d\u5386,\u76f8\u4fe1\u90fd\u4e0d\u964c\u751f,\u5728\u5e73\u5e38\u7684\u4e8b\u4ef6\u5904\u7406\u4e2d,\u662ffor\u5faa\u73af\u7684\u53d8\u4f53,\u4f46\u6bd4for\u5faa\u73af\u5f3a\u5927.\u5728\u6570\u7ec4\u4e2d,\u5b83\u53ef\u4ee5\u8f7b\u677e\u7684\u653b\u53d6\u6570\u7ec4\u7d22\u5f15\u53ca\u5bf9\u5e94\u7684\u503c.\u4f8b:<\/p>\n<div style=\"border-bottom:#dddddd 1px solid;text-align:left;border-left:#dddddd 1px solid;padding-bottom:0px;background-color:#f7f7f7;margin:0px 0px 7px;padding-left:5px;padding-right:5px;font:13px\/22px 'Courier New', Courier, monospace;letter-spacing:0px;border-top:#dddddd 1px solid;border-right:#dddddd 1px solid;padding-top:0px;text-shadow:#ffffff 0px 1px 0px;background-origin:initial;background-clip:initial;\" class=\"hl-surround\">\n<div style=\"padding-bottom:0px;line-height:1.5;margin:0px;padding-left:0px;padding-right:0px;padding-top:0px;\" class=\"hl-main\"><span style=\"color:green;\">var<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">_mozi<\/span><span style=\"color:gray;\">=<\/span><span style=\"color:olive;\">[<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u58a8\u5bb6<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u58a8\u5b50<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u58a8\u7fdf<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u517c\u7231\u975e\u653b<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u5c1a\u540c\u5c1a\u8d24<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:olive;\">]<\/span><span style=\"color:gray;\">;&nbsp;<\/span><span style=\"color:#ffa500;\">\/\/\u672c\u6587\u6240\u7528\u5230\u7684\u6570\u7ec4, \u4e0b\u540c<\/span><span style=\"color:gray;\"><br \/>\n$.<\/span><span style=\"color:blue;\">each<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">_mozi<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:green;\">function<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">key<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:blue;\">val<\/span><span style=\"color:olive;\">){<\/span><span style=\"color:gray;\"><br \/>\n&nbsp;&nbsp; &nbsp;<\/span><span style=\"color:#ffa500;\">\/\/\u56de\u8c03\u51fd\u6570\u6709\u4e24\u4e2a\u53c2\u6570,\u7b2c\u4e00\u4e2a\u662f\u5143\u7d20\u7d22\u5f15,\u7b2c\u4e8c\u4e2a\u4e3a\u5f53\u524d\u503c<\/span><span style=\"color:gray;\"><br \/>\n&nbsp;&nbsp; &nbsp;<\/span><span style=\"color:blue;\">alert<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">_mozi\u6570\u7ec4\u4e2d ,\u7d22\u5f15 :&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:blue;\">key<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">&nbsp;\u5bf9\u5e94\u7684\u503c\u4e3a:&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:blue;\">val<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:olive;\">})<\/span><span style=\"color:gray;\">;<\/span><\/div>\n<\/div>\n<p style=\"padding-bottom:0px;line-height:1.8;margin:0px 0px 5px;padding-left:0px;padding-right:0px;padding-top:0px;\">\u76f8\u5bf9\u4e8e\u539f\u751f\u7684for..in,each\u66f4\u5f3a\u58ee\u4e00\u70b9. for..in\u4e5f\u53ef\u4ee5\u904d\u5386\u6570\u7ec4,\u5e76\u8fd4\u56de\u5bf9\u5e94\u7d22\u5f15,\u4f46\u503c\u662f\u9700\u8981\u901a\u8fc7arrName[key]\u6765\u83b7\u53d6;<br style=\"margin-bottom:7px;\" \/><br \/>\n<strong style=\"margin-right:3px;\">2. $.grep(array, callback, [invert]) \u8fc7\u6ee4\u6570\u7ec4<\/strong>[\u5e38\u7528]<br style=\"margin-bottom:7px;\" \/><br \/>\n<strong style=\"margin-right:3px;\">\u89e3\u91ca:&nbsp;<\/strong>\u4f7f\u7528\u8fc7\u6ee4\u51fd\u6570\u8fc7\u6ee4\u6570\u7ec4\u5143\u7d20.\u6b64\u51fd\u6570\u81f3\u5c11\u4f20\u9012\u4e24\u4e2a\u53c2\u6570(\u7b2c\u4e09\u4e2a\u53c2\u6570\u4e3atrue\u6216false,\u5bf9\u8fc7\u6ee4\u51fd\u6570\u8fd4\u56de\u503c\u53d6\u53cd,\u4e2a\u4eba\u89c9\u5f97\u7528\u5904\u4e0d\u5927): \u5f85\u8fc7\u6ee4\u6570\u7ec4\u548c\u8fc7\u6ee4\u51fd\u6570. \u8fc7\u6ee4\u51fd\u6570\u5fc5\u987b\u8fd4\u56de true \u4ee5\u4fdd\u7559\u5143\u7d20\u6216 false \u4ee5\u5220\u9664\u5143\u7d20. \u53e6\u5916,\u8fc7\u6ee4\u51fd\u6570\u8fd8\u53ef\u4ee5\u662f\u53ef\u8bbe\u7f6e\u4e3a\u4e00\u4e2a\u5b57\u6761\u4e32(\u4e2a\u4eba\u4e0d\u63a8\u8350,\u6b32\u4e86\u89e3\u81ea\u884c\u67e5\u9605);<\/p>\n<div style=\"border-bottom:#dddddd 1px solid;text-align:left;border-left:#dddddd 1px solid;padding-bottom:0px;background-color:#f7f7f7;margin:0px 0px 7px;padding-left:5px;padding-right:5px;font:13px\/22px 'Courier New', Courier, monospace;letter-spacing:0px;border-top:#dddddd 1px solid;border-right:#dddddd 1px solid;padding-top:0px;text-shadow:#ffffff 0px 1px 0px;background-origin:initial;background-clip:initial;\" class=\"hl-surround\">\n<div style=\"padding-bottom:0px;line-height:1.5;margin:0px;padding-left:0px;padding-right:0px;padding-top:0px;\" class=\"hl-main\"><span style=\"color:gray;\">$.<\/span><span style=\"color:blue;\">grep<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">_mozi<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:green;\">function<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">val<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:blue;\">key<\/span><span style=\"color:olive;\">){<\/span><span style=\"color:gray;\"><br \/>\n&nbsp;&nbsp; &nbsp;<\/span><span style=\"color:#ffa500;\">\/\/\u8fc7\u6ee4\u51fd\u6570\u6709\u4e24\u4e2a\u53c2\u6570,\u7b2c\u4e00\u4e2a\u4e3a\u5f53\u524d\u5143\u7d20,\u7b2c\u4e8c\u4e2a\u4e3a\u5143\u7d20\u7d22\u5f15<\/span><span style=\"color:gray;\"><br \/>\n&nbsp;&nbsp; &nbsp;<\/span><span style=\"color:green;\">if<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">val<\/span><span style=\"color:gray;\">==<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u58a8\u5b50<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:olive;\">){<\/span><span style=\"color:gray;\"><br \/>\n&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<\/span><span style=\"color:blue;\">alert<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u6570\u7ec4\u503c\u4e3a \u58a8\u5b50 \u7684\u4e0b\u6807\u662f:&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:blue;\">key<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<br \/>\n&nbsp;&nbsp; &nbsp;<\/span><span style=\"color:olive;\">}<\/span><span style=\"color:gray;\"><br \/>\n<\/span><span style=\"color:olive;\">})<\/span><span style=\"color:gray;\">;<br \/>\n&nbsp;<br \/>\n<\/span><span style=\"color:green;\">var<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">_moziGt1<\/span><span style=\"color:gray;\">=$.<\/span><span style=\"color:blue;\">grep<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">_mozi<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:green;\">function<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">val<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:blue;\">key<\/span><span style=\"color:olive;\">){<\/span><span style=\"color:gray;\"><br \/>\n&nbsp;&nbsp; &nbsp;<\/span><span style=\"color:green;\">return<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">key<\/span><span style=\"color:gray;\">&gt;<\/span><span style=\"color:maroon;\">1<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:olive;\">})<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:blue;\">alert<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">_mozi\u6570\u7ec4\u4e2d\u7d22\u5f15\u503c\u5927\u4e8e1\u7684\u5143\u7d20\u4e3a:&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:blue;\">_moziGt1<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<br \/>\n&nbsp;<br \/>\n<\/span><span style=\"color:green;\">var<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">_moziLt1<\/span><span style=\"color:gray;\">=$.<\/span><span style=\"color:blue;\">grep<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">_mozi<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:green;\">function<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">val<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:blue;\">key<\/span><span style=\"color:olive;\">){<\/span><span style=\"color:gray;\"><br \/>\n&nbsp;&nbsp; &nbsp;<\/span><span style=\"color:green;\">return<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">key<\/span><span style=\"color:gray;\">&gt;<\/span><span style=\"color:maroon;\">1<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:olive;\">}<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:green;\">true<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:#ffa500;\">\/\/\u6b64\u5904\u4f20\u5165\u4e86\u7b2c\u4e09\u4e2a\u53ef\u9760\u53c2\u6570,\u5bf9\u8fc7\u6ee4\u51fd\u6570\u4e2d\u7684\u8fd4\u56de\u503c\u53d6\u53cd<\/span><span style=\"color:gray;\"><br \/>\n<\/span><span style=\"color:blue;\">alert<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">_mozi\u6570\u7ec4\u4e2d\u7d22\u5f15\u503c\u5c0f\u4e8e\u7b49\u4e8e1\u7684\u5143\u7d20\u4e3a:&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:blue;\">_moziLt1<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<\/span><\/div>\n<\/div>\n<p style=\"padding-bottom:0px;line-height:1.8;margin:0px 0px 5px;padding-left:0px;padding-right:0px;padding-top:0px;\"><strong style=\"margin-right:3px;\">3. $.map(array,[callback])\u6309\u7ed9\u5b9a\u6761\u4ef6\u8f6c\u6362\u6570\u7ec4&nbsp;<\/strong>[\u4e00\u822c]<br style=\"margin-bottom:7px;\" \/><br \/>\n<strong style=\"margin-right:3px;\">\u89e3\u91ca:<\/strong>\u4f5c\u4e3a\u53c2\u6570\u7684\u8f6c\u6362\u51fd\u6570\u4f1a\u4e3a\u6bcf\u4e2a\u6570\u7ec4\u5143\u7d20\u8c03\u7528, \u800c\u4e14\u4f1a\u7ed9\u8fd9\u4e2a\u8f6c\u6362\u51fd\u6570\u4f20\u9012\u4e00\u4e2a\u8868\u793a\u88ab\u8f6c\u6362\u7684\u5143\u7d20\u4f5c\u4e3a\u53c2\u6570. \u8f6c\u6362\u51fd\u6570\u53ef\u4ee5\u8fd4\u56de\u8f6c\u6362\u540e\u7684\u503c\u3001null(\u5220\u9664\u6570\u7ec4\u4e2d\u7684\u9879\u76ee)\u6216\u4e00\u4e2a\u5305\u542b\u503c\u7684\u6570\u7ec4, \u5e76\u6269\u5c55\u81f3\u539f\u59cb\u6570\u7ec4\u4e2d.<br style=\"margin-bottom:7px;\" \/><br \/>\n\u8fd9\u4e2a\u662f\u4e2a\u5f88\u5f3a\u5927\u7684\u65b9\u6cd5,\u4f46\u5e76\u4e0d\u5e38\u7528. \u5b83\u53ef\u4ee5\u6839\u636e\u7279\u5b9a\u6761\u4ef6,\u66f4\u65b0\u6570\u7ec4\u5143\u7d20\u503c,\u6216\u6839\u636e\u539f\u503c\u6269\u5c55\u4e00\u4e2a\u65b0\u7684\u526f\u672c\u5143\u7d20.<\/p>\n<div style=\"border-bottom:#dddddd 1px solid;text-align:left;border-left:#dddddd 1px solid;padding-bottom:0px;background-color:#f7f7f7;margin:0px 0px 7px;padding-left:5px;padding-right:5px;font:13px\/22px 'Courier New', Courier, monospace;letter-spacing:0px;border-top:#dddddd 1px solid;border-right:#dddddd 1px solid;padding-top:0px;text-shadow:#ffffff 0px 1px 0px;background-origin:initial;background-clip:initial;\" class=\"hl-surround\">\n<div style=\"padding-bottom:0px;line-height:1.5;margin:0px;padding-left:0px;padding-right:0px;padding-top:0px;\" class=\"hl-main\"><span style=\"color:green;\">var<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">_mapArrA<\/span><span style=\"color:gray;\">=$.<\/span><span style=\"color:blue;\">map<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">_mozi<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:green;\">function<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">val<\/span><span style=\"color:olive;\">){<\/span><span style=\"color:gray;\"><br \/>\n&nbsp;&nbsp; &nbsp;<\/span><span style=\"color:green;\">return<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">val<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">[\u65b0\u52a0]<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:olive;\">})<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:green;\">var<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">_mapArrB<\/span><span style=\"color:gray;\">=$.<\/span><span style=\"color:blue;\">map<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">_mozi<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:green;\">function<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">val<\/span><span style=\"color:olive;\">){<\/span><span style=\"color:gray;\"><br \/>\n&nbsp;&nbsp; &nbsp;<\/span><span style=\"color:green;\">return<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">val<\/span><span style=\"color:gray;\">==<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u58a8\u5b50<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">&nbsp;?&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">[\u53ea\u7ed9\u58a8\u5b50\u52a0]<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:blue;\">val<\/span><span style=\"color:gray;\">&nbsp;:&nbsp;<\/span><span style=\"color:blue;\">val<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:olive;\">})<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:green;\">var<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">_mapArrC<\/span><span style=\"color:gray;\">=$.<\/span><span style=\"color:blue;\">map<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">_mozi<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:green;\">function<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">val<\/span><span style=\"color:olive;\">){<\/span><span style=\"color:gray;\"><br \/>\n&nbsp;&nbsp; &nbsp;<\/span><span style=\"color:#ffa500;\">\/\/\u4e3a\u6570\u7ec4\u5143\u7d20\u6269\u5c55\u4e00\u4e2a\u65b0\u5143\u7d20<\/span><span style=\"color:gray;\"><br \/>\n&nbsp;&nbsp; &nbsp;<\/span><span style=\"color:green;\">return<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:olive;\">[<\/span><span style=\"color:blue;\">val<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">val<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">[\u6269\u5c55]<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:olive;\">)]<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:olive;\">})<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:blue;\">alert<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u5728\u6bcf\u4e2a\u5143\u7d20\u540e\u9762\u52a0<\/span><span style=\"color:navy;\">\\'<\/span><span style=\"color:red;\">[\u65b0\u52a0]<\/span><span style=\"color:navy;\">\\'<\/span><span style=\"color:red;\">\u5b57\u7b26\u540e\u7684\u6570\u7ec4\u4e3a:&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+&nbsp;<\/span><span style=\"color:blue;\">_mapArrA<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:blue;\">alert<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u53ea\u7ed9\u5143\u7d20 \u58a8\u5b50 \u6dfb\u52a0\u5b57\u7b26\u540e\u7684\u6570\u7ec4\u4e3a:&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+&nbsp;<\/span><span style=\"color:blue;\">_mapArrB<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:blue;\">alert<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u4e3a\u539f\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20,\u6269\u5c55\u4e00\u4e2a\u6dfb\u52a0\u5b57\u7b26<\/span><span style=\"color:navy;\">\\'<\/span><span style=\"color:red;\">[\u65b0\u52a0]<\/span><span style=\"color:navy;\">\\'<\/span><span style=\"color:red;\">\u7684\u5143\u7d20,\u8fd4\u56de\u7684\u6570\u7ec4\u4e3a&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:blue;\">_mapArrC<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<\/span><\/div>\n<\/div>\n<p style=\"padding-bottom:0px;line-height:1.8;margin:0px 0px 5px;padding-left:0px;padding-right:0px;padding-top:0px;\"><strong style=\"margin-right:3px;\">4 .$.inArray(val,array)\u5224\u65ad\u503c\u662f\u5426\u5b58\u5728\u4e8e\u6570\u7ec4\u4e2d<\/strong>[\u5e38\u7528]<br style=\"margin-bottom:7px;\" \/><br \/>\n<strong style=\"margin-right:3px;\">\u89e3\u91ca:&nbsp;<\/strong>\u786e\u5b9a\u7b2c\u4e00\u4e2a\u53c2\u6570\u5728\u6570\u7ec4\u4e2d\u7684\u4f4d\u7f6e, \u4ece0\u5f00\u59cb\u8ba1\u6570(\u5982\u679c\u6ca1\u6709\u627e\u5230\u5219\u8fd4\u56de -1 ).<br style=\"margin-bottom:7px;\" \/><br \/>\n\u8bb0\u5f97indexOf()\u65b9\u6cd5\u4e86\u5417? indexOf()\u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u9996\u6b21\u51fa\u73b0\u4f4d\u7f6e,\u800c$.inArray()\u8fd4\u56de\u7684\u662f\u4f20\u5165\u53c2\u6570\u5728\u6570\u7ec4\u4e2d\u7684\u4f4d\u7f6e,\u540c\u6837\u7684,\u5982\u679c\u627e\u5230\u7684,\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u5927\u4e8e\u6216\u7b49\u4e8e0\u7684\u503c,\u82e5\u672a\u627e\u5230\u5219\u8fd4\u56de-1.\u73b0\u5728, \u77e5\u9053\u600e\u4e48\u7528\u4e86\u5427. \u6709\u4e86\u5b83, \u5224\u65ad\u67d0\u4e2a\u503c\u662f\u5426\u5b58\u5728\u4e8e\u6570\u7ec4\u4e2d,\u5c31\u53d8\u5f97\u8f7b\u800c\u6613\u4e3e\u4e86.<\/p>\n<div style=\"border-bottom:#dddddd 1px solid;text-align:left;border-left:#dddddd 1px solid;padding-bottom:0px;background-color:#f7f7f7;margin:0px 0px 7px;padding-left:5px;padding-right:5px;font:13px\/22px 'Courier New', Courier, monospace;letter-spacing:0px;border-top:#dddddd 1px solid;border-right:#dddddd 1px solid;padding-top:0px;text-shadow:#ffffff 0px 1px 0px;background-origin:initial;background-clip:initial;\" class=\"hl-surround\">\n<div style=\"padding-bottom:0px;line-height:1.5;margin:0px;padding-left:0px;padding-right:0px;padding-top:0px;\" class=\"hl-main\"><span style=\"color:green;\">var<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">_exist<\/span><span style=\"color:gray;\">=$.<\/span><span style=\"color:blue;\">inArray<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u58a8\u5b50<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:blue;\">_mozi<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:green;\">var<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">_inexistence<\/span><span style=\"color:gray;\">=$.<\/span><span style=\"color:blue;\">inArray<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u536b\u9785<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:blue;\">_mozi<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\"><br \/>\n<\/span><span style=\"color:green;\">if<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">_exist<\/span><span style=\"color:gray;\">&gt;=<\/span><span style=\"color:maroon;\">0<\/span><span style=\"color:olive;\">){<\/span><span style=\"color:gray;\"><br \/>\n&nbsp;&nbsp; &nbsp;<\/span><span style=\"color:blue;\">alert<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u58a8\u5b50 \u5b58\u5728\u4e8e\u6570\u7ec4_mozi\u4e2d,\u5176\u5728\u6570\u7ec4\u4e2d\u7d22\u5f15\u503c\u662f:&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:blue;\">_exist<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:olive;\">}<\/span><span style=\"color:gray;\"><br \/>\n<\/span><span style=\"color:green;\">if<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">_inexistence<\/span><span style=\"color:gray;\">&lt;<\/span><span style=\"color:maroon;\">0<\/span><span style=\"color:olive;\">){<\/span><span style=\"color:gray;\"><br \/>\n&nbsp;&nbsp; &nbsp;<\/span><span style=\"color:blue;\">alert<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u536b\u9785 \u4e0d\u5b58\u5728\u4e8e\u6570\u7ec4_mozi\u4e2d!,\u8fd4\u56de\u503c\u4e3a:&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:blue;\">_inexistence<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">!<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:olive;\">}<\/span><\/div>\n<\/div>\n<p style=\"padding-bottom:0px;line-height:1.8;margin:0px 0px 5px;padding-left:0px;padding-right:0px;padding-top:0px;\"><strong style=\"margin-right:3px;\">5 .$.merge(first,second)\u5408\u5e76\u4e24\u4e2a\u6570\u7ec4<\/strong>[\u4e00\u822c]<br style=\"margin-bottom:7px;\" \/><br \/>\n<strong style=\"margin-right:3px;\">\u89e3\u91ca:&nbsp;<\/strong>\u8fd4\u56de\u7684\u7ed3\u679c\u4f1a\u4fee\u6539\u7b2c\u4e00\u4e2a\u6570\u7ec4\u7684\u5185\u5bb9\u2014\u2014\u7b2c\u4e00\u4e2a\u6570\u7ec4\u7684\u5143\u7d20\u540e\u9762\u8ddf\u7740\u7b2c\u4e8c\u4e2a\u6570\u7ec4\u7684\u5143\u7d20.<br style=\"margin-bottom:7px;\" \/><br \/>\n\u8fd9\u4e2a\u65b9\u6cd5\u662f\u7528jQuery\u7684\u65b9\u6cd5\u66ff\u4ee3\u539f\u751fconcat()\u65b9\u6cd5, \u4f46\u529f\u80fd\u5e76\u6ca1\u6709concat()\u5f3a\u5927, concat()\u53ef\u4ee5\u540c\u65f6\u5408\u5e76\u591a\u4e2a\u6570\u7ec4.<\/p>\n<div style=\"border-bottom:#dddddd 1px solid;text-align:left;border-left:#dddddd 1px solid;padding-bottom:0px;background-color:#f7f7f7;margin:0px 0px 7px;padding-left:5px;padding-right:5px;font:13px\/22px 'Courier New', Courier, monospace;letter-spacing:0px;border-top:#dddddd 1px solid;border-right:#dddddd 1px solid;padding-top:0px;text-shadow:#ffffff 0px 1px 0px;background-origin:initial;background-clip:initial;\" class=\"hl-surround\">\n<div style=\"padding-bottom:0px;line-height:1.5;margin:0px;padding-left:0px;padding-right:0px;padding-top:0px;\" class=\"hl-main\"><span style=\"color:#ffa500;\">\/\/\u539f\u751fconcat()\u53ef\u80fd\u6bd4\u5b83\u8fd8\u7b80\u6d01\u70b9<\/span><span style=\"color:gray;\"><br \/>\n<\/span><span style=\"color:blue;\">_moziNew<\/span><span style=\"color:gray;\">=$.<\/span><span style=\"color:blue;\">merge<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">_mozi<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:olive;\">[<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u9b3c\u8c37\u5b50<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u5546\u9785<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u5b59\u8191<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u5e9e\u6d93<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u82cf\u79e6<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u5f20\u4eea<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:olive;\">])<\/span><span style=\"color:gray;\"><br \/>\n<\/span><span style=\"color:blue;\">alert<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u5408\u5e76\u540e\u65b0\u6570\u7ec4\u957f\u5ea6\u4e3a:&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:blue;\">_moziNew<\/span><span style=\"color:gray;\">.<\/span><span style=\"color:blue;\">length<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">. \u5176\u503c\u4e3a:&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:blue;\">_moziNew<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<\/span><\/div>\n<\/div>\n<p style=\"padding-bottom:0px;line-height:1.8;margin:0px 0px 5px;padding-left:0px;padding-right:0px;padding-top:0px;\"><strong style=\"margin-right:3px;\">6 .$.unique(array)\u8fc7\u6ee4\u6570\u7ec4\u4e2d\u91cd\u590d\u5143\u7d20<\/strong>[\u4e0d\u5e38\u7528]<br style=\"margin-bottom:7px;\" \/><br \/>\n<strong style=\"margin-right:3px;\">\u89e3\u91ca:&nbsp;<\/strong>\u5220\u9664\u6570\u7ec4\u4e2d\u91cd\u590d\u5143\u7d20. \u53ea\u5904\u7406\u5220\u9664DOM\u5143\u7d20\u6570\u7ec4,\u800c\u4e0d\u80fd\u5904\u7406\u5b57\u7b26\u4e32\u6216\u8005\u6570\u5b57\u6570\u7ec4.<br style=\"margin-bottom:7px;\" \/><br \/>\n\u7b2c\u4e00\u6b21\u770b\u5230\u8fd9\u4e2a\u65b9\u6cd5,\u89c9\u5f97\u8fd9\u662f\u4e2a\u5f88\u4fbf\u6377\u7684\u65b9\u6cd5, \u53ef\u4ee5\u8fc7\u6ee4\u91cd\u590d, \u54c8, \u591a\u5b8c\u7f8e, \u4f46\u4ed4\u7ec6\u4e00\u770b, \u4ec5\u9650\u5904\u7406DOM\u5143\u7d20. \u529f\u80fd8\u6298\u4e86.\u6240\u4ee5, \u6211\u7ed9\u5b83\u5b9a\u4e49\u6210\u4e86\u4e00\u4e2a\u4e0d\u5e38\u7528\u7684\u5143\u7d20, \u81f3\u5c11, \u6211\u7528jQuery\u4ee5\u6765\u6ca1\u7528\u5230\u8fc7\u5b83.<\/p>\n<div style=\"border-bottom:#dddddd 1px solid;text-align:left;border-left:#dddddd 1px solid;padding-bottom:0px;background-color:#f7f7f7;margin:0px 0px 7px;padding-left:5px;padding-right:5px;font:13px\/22px 'Courier New', Courier, monospace;letter-spacing:0px;border-top:#dddddd 1px solid;border-right:#dddddd 1px solid;padding-top:0px;text-shadow:#ffffff 0px 1px 0px;background-origin:initial;background-clip:initial;\" class=\"hl-surround\">\n<div style=\"padding-bottom:0px;line-height:1.5;margin:0px;padding-left:0px;padding-right:0px;padding-top:0px;\" class=\"hl-main\"><span style=\"color:green;\">var<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">_h2Arr<\/span><span style=\"color:gray;\">=$.<\/span><span style=\"color:blue;\">makeArray<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">h2obj<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:#ffa500;\">\/\/\u5c06\u6570\u7ec4_h2Arr\u91cd\u590d\u4e00\u6b21<\/span><span style=\"color:gray;\"><br \/>\n<\/span><span style=\"color:blue;\">_h2Arr<\/span><span style=\"color:gray;\">=$.<\/span><span style=\"color:blue;\">merge<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">_h2Arr<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:blue;\">_h2Arr<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:green;\">var<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">_curLen<\/span><span style=\"color:gray;\">=<\/span><span style=\"color:blue;\">_h2Arr<\/span><span style=\"color:gray;\">.<\/span><span style=\"color:blue;\">length<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:blue;\">_h2Arr<\/span><span style=\"color:gray;\">=$.<\/span><span style=\"color:blue;\">unique<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">_h2Arr<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:green;\">var<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">_newLen<\/span><span style=\"color:gray;\">=<\/span><span style=\"color:blue;\">_h2Arr<\/span><span style=\"color:gray;\">.<\/span><span style=\"color:blue;\">length<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:blue;\">alert<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u6570\u7ec4_h2Arr\u539f\u957f\u5ea6\u503c\u4e3a:&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:blue;\">_curLen<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">&nbsp;,\u8fc7\u6ee4\u540e\u4e3a:&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:blue;\">_newLen<\/span><span style=\"color:gray;\"><br \/>\n&nbsp;&nbsp; &nbsp; &nbsp;+<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">&nbsp;.\u5171\u8fc7\u6ee4&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">_curLen<\/span><span style=\"color:gray;\">-<\/span><span style=\"color:blue;\">_newLen<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u4e2a\u91cd\u590d\u5143\u7d20<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:olive;\">)<\/span><\/div>\n<\/div>\n<p style=\"padding-bottom:0px;line-height:1.8;margin:0px 0px 5px;padding-left:0px;padding-right:0px;padding-top:0px;\"><strong style=\"margin-right:3px;\">7. $.makeArray(obj) \u5c06\u7c7b\u6570\u7ec4\u5bf9\u8c61\u8f6c\u6362\u4e3a\u6570\u7ec4<\/strong>[\u4e0d\u5e38\u7528]<br style=\"margin-bottom:7px;\" \/><br \/>\n<strong style=\"margin-right:3px;\">\u89e3\u91ca:&nbsp;<\/strong>\u5c06\u7c7b\u6570\u7ec4\u5bf9\u8c61\u8f6c\u6362\u4e3a\u6570\u7ec4\u5bf9\u8c61, \u7c7b\u6570\u7ec4\u5bf9\u8c61\u6709 length \u5c5e\u6027,\u5176\u6210\u5458\u7d22\u5f15\u4e3a0\u81f3 length-1.<br style=\"margin-bottom:7px;\" \/><br \/>\n\u8fd9\u662f\u4e2a\u591a\u4f59\u7684\u65b9\u6cd5, \u65e0\u6240\u4e0d\u80fd\u7684$\u672c\u6765\u5c31\u5305\u542b\u4e86\u8fd9\u4e2a\u529f\u80fd. jQuery\u5b98\u7f51\u4e0a\u89e3\u91ca\u7684\u975e\u5e38\u6a21\u7cca. \u5176\u5b9e, \u5b83\u5c31\u662f\u5c06\u67d0\u4e2a\u7c7b\u6570\u7ec4\u5bf9\u8c61(\u6bd4\u5982\u7528getElementsByTagName\u83b7\u53d6\u7684\u5143\u7d20\u5bf9\u8c61\u96c6\u5408)\u8f6c\u6362\u6210\u6570\u7ec4\u5bf9\u8c61.<\/p>\n<div style=\"border-bottom:#dddddd 1px solid;text-align:left;border-left:#dddddd 1px solid;padding-bottom:0px;background-color:#f7f7f7;margin:0px 0px 7px;padding-left:5px;padding-right:5px;font:13px\/22px 'Courier New', Courier, monospace;letter-spacing:0px;border-top:#dddddd 1px solid;border-right:#dddddd 1px solid;padding-top:0px;text-shadow:#ffffff 0px 1px 0px;background-origin:initial;background-clip:initial;\" class=\"hl-surround\">\n<div style=\"padding-bottom:0px;line-height:1.5;margin:0px;padding-left:0px;padding-right:0px;padding-top:0px;\" class=\"hl-main\"><span style=\"color:green;\">var<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">_makeArr<\/span><span style=\"color:gray;\">=$.<\/span><span style=\"color:blue;\">makeArray<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:blue;\">h2obj<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:blue;\">alert<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">h2\u5143\u7d20\u5bf9\u8c61\u96c6\u5408\u7684\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u4e3a:&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:blue;\">_makeArr<\/span><span style=\"color:gray;\">.<\/span><span style=\"color:blue;\">constructor<\/span><span style=\"color:gray;\">.<\/span><span style=\"color:blue;\">name<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<\/span><span style=\"color:#ffa500;\">\/\/\u8f93\u51faArray<\/span><\/div>\n<\/div>\n<p style=\"padding-bottom:0px;line-height:1.8;margin:0px 0px 5px;padding-left:0px;padding-right:0px;padding-top:0px;\"><strong style=\"margin-right:3px;\">8. $(dom).toArray()\u5c06\u6240\u6709DOM\u5143\u7d20\u6062\u590d\u6210\u6570\u7ec4<\/strong>[\u4e0d\u5e38\u7528]<br style=\"margin-bottom:7px;\" \/><br \/>\n<strong style=\"margin-right:3px;\">\u89e3\u91ca:&nbsp;<\/strong>\u628ajQuery\u96c6\u5408\u4e2d\u6240\u6709DOM\u5143\u7d20\u6062\u590d\u6210\u4e00\u4e2a\u6570\u7ec4;<br style=\"margin-bottom:7px;\" \/><br \/>\n\u5e76\u4e0d\u5e38\u7528\u7684\u65b9\u6cd5, \u4e2a\u4eba\u751a\u81f3\u89c9\u5f97\u5b83\u548c$.makeArray\u4e00\u6837\u591a\u4f59.<\/p>\n<div style=\"border-bottom:#dddddd 1px solid;text-align:left;border-left:#dddddd 1px solid;padding-bottom:0px;background-color:#f7f7f7;margin:0px 0px 7px;padding-left:5px;padding-right:5px;font:13px\/22px 'Courier New', Courier, monospace;letter-spacing:0px;border-top:#dddddd 1px solid;border-right:#dddddd 1px solid;padding-top:0px;text-shadow:#ffffff 0px 1px 0px;background-origin:initial;background-clip:initial;\" class=\"hl-surround\">\n<div style=\"padding-bottom:0px;line-height:1.5;margin:0px;padding-left:0px;padding-right:0px;padding-top:0px;\" class=\"hl-main\"><span style=\"color:green;\">var<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">_toArr<\/span><span style=\"color:gray;\">=$<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">h2<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">.<\/span><span style=\"color:blue;\">toArray<\/span><span style=\"color:olive;\">()<\/span><span style=\"color:gray;\">;<br \/>\n<\/span><span style=\"color:blue;\">alert<\/span><span style=\"color:olive;\">(<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">h2\u5143\u7d20\u96c6\u5408\u6062\u590d\u540e\u7684\u6570\u636e\u7c7b\u578b\u662f:&nbsp;<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">+<\/span><span style=\"color:blue;\">_toArr<\/span><span style=\"color:gray;\">.<\/span><span style=\"color:blue;\">constructor<\/span><span style=\"color:gray;\">.<\/span><span style=\"color:blue;\">name<\/span><span style=\"color:olive;\">)<\/span><span style=\"color:gray;\">;<\/span><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p><strong>1. $.each(array, [callback]) \u904d\u5386<\/strong>[\u5e38\u7528]<br style=\"margin-bottom:7px;\" \/><strong style=\"margin-right:3px;\">\u89e3\u91ca:&nbsp;<\/strong>\u4e0d\u540c\u4e8e\u4f8b\u904d jQuery \u5bf9\u8c61\u7684 $().each() \u65b9\u6cd5,\u6b64\u65b9\u6cd5\u53ef\u7528\u4e8e\u4f8b\u904d\u4efb\u4f55\u5bf9\u8c61(\u4e0d\u4ec5\u4ec5\u662f\u6570\u7ec4\u54e6~). \u56de\u8c03\u51fd\u6570\u62e5\u6709\u4e24\u4e2a\u53c2\u6570\uff1a\u7b2c\u4e00\u4e2a\u4e3a\u5bf9\u8c61\u7684\u6210\u5458\u6216\u6570\u7ec4\u7684\u7d22\u5f15, \u7b2c\u4e8c\u4e2a\u4e3a\u5bf9\u5e94\u53d8\u91cf\u6216\u5185\u5bb9. \u5982\u679c\u9700\u8981\u9000\u51fa each \u5faa\u73af\u53ef\u4f7f\u56de\u8c03\u51fd\u6570\u8fd4\u56de false, \u5176\u5b83\u8fd4\u56de\u503c\u5c06\u88ab\u5ffd\u7565.<br style=\"margin-bottom:7px;\" \/><br \/>\neach\u904d\u5386,\u76f8\u4fe1\u90fd\u4e0d\u964c\u751f,\u5728\u5e73\u5e38\u7684\u4e8b\u4ef6\u5904\u7406\u4e2d,\u662ffor\u5faa\u73af\u7684\u53d8\u4f53,\u4f46\u6bd4for\u5faa\u73af\u5f3a\u5927.\u5728\u6570\u7ec4\u4e2d,\u5b83\u53ef\u4ee5\u8f7b\u677e\u7684\u653b\u53d6\u6570\u7ec4\u7d22\u5f15\u53ca\u5bf9\u5e94\u7684\u503c.\u4f8b:<\/p>\n<div style=\"border-bottom:#dddddd 1px solid;text-align:left;border-left:#dddddd 1px solid;padding-bottom:0px;background-color:#f7f7f7;margin:0px 0px 7px;padding-left:5px;padding-right:5px;font:13px\/22px 'Courier New', Courier, monospace;letter-spacing:0px;border-top:#dddddd 1px solid;border-right:#dddddd 1px solid;padding-top:0px;text-shadow:#ffffff 0px 1px 0px;background-origin:initial;background-clip:initial;\" class=\"hl-surround\">\n<div style=\"padding-bottom:0px;line-height:1.5;margin:0px;padding-left:0px;padding-right:0px;padding-top:0px;\" class=\"hl-main\"><span style=\"color:green;\">var<\/span><span style=\"color:gray;\">&nbsp;<\/span><span style=\"color:blue;\">_mozi<\/span><span style=\"color:gray;\">=<\/span><span style=\"color:olive;\">[<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u58a8\u5bb6<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u58a8\u5b50<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u58a8\u7fdf<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u517c\u7231\u975e\u653b<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:gray;\">,<\/span><span style=\"color:#8b0000;\">'<\/span><span style=\"color:red;\">\u5c1a...<\/span><\/div>\n<\/div>\n<p> <a href=\"https:\/\/www.xiaobo.li\/notes\/archives\/233\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[273],"tags":[75,9],"class_list":["post-233","post","type-post","status-publish","format-standard","hentry","category-article","tag-jquery","tag-js"],"_links":{"self":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/comments?post=233"}],"version-history":[{"count":0,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/233\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/media?parent=233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/categories?post=233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/tags?post=233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}