{"id":1085,"date":"2009-09-02T15:51:48","date_gmt":"2009-09-02T07:51:48","guid":{"rendered":"http:\/\/www.nan.im\/blog\/?p=1085"},"modified":"2009-09-02T15:51:48","modified_gmt":"2009-09-02T07:51:48","slug":"%e4%bd%bf%e7%94%a8-js-jquery-%e6%8e%a7%e5%88%b6%e9%93%be%e6%8e%a5%e5%9c%a8%e6%96%b0%e7%aa%97%e5%8f%a3-_blank-%e6%89%93%e5%bc%80","status":"publish","type":"post","link":"http:\/\/nan.im\/blog\/1085","title":{"rendered":"\u3010jQuery\u3011\u4f7f\u7528 js &amp; jQuery \u63a7\u5236\u94fe\u63a5\u5728\u65b0\u7a97\u53e3 _blank \u6253\u5f00"},"content":{"rendered":"<p>\u65e2\u7136 W3C \u4e25\u683c\u6807\u51c6\u5c06 target=\u201d_blank\u201d \u5c5e\u6027\u5254\u9664\uff0c\u539f\u56e0\u662f W3C \u8ba4\u4e3a\u672a\u7ecf\u7528\u6237\u540c\u610f\u5c31\u6253\u5f00\u65b0\u7a97\u53e3\u662f\u4e00\u79cd\u4e0d\u793c\u8c8c\u7684\u884c\u4e3a\uff0c\u5bb9\u6613\u7834\u574f\u7528\u6237\u4f53\u9a8c\u3002\u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff0c\u5982\u4f55\u80fd\u5373\u7b26\u5408 W3C \u4e25\u683c\u6807\u51c6\u53c8\u80fd\u4f7f\u9875\u9762\u5728\u65b0\u7a97\u53e3\u6253\u5f00\u5462\uff1f\u6309 W3C \u7684\u610f\u601d\u662f\u4e3a\u9700\u8981\u5f39\u51fa\u65b0\u7a97\u53e3\u7684 a \u94fe\u63a5\u6807\u8bb0\u6dfb\u52a0\u4e00\u4e2a rel=&#8221;external&#8221; \u5c5e\u6027\uff0c\u6216\u8bb8\u7b49\u8fd9\u79cd\u6807\u51c6\u666e\u53ca\u4ee5\u540e\u53ef\u4ee5\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbe\u7f6e\u662f\u5426\u5f39\u51fa\u5305\u542b\u6709 rel=&#8221;external&#8221; \u5c5e\u6027\u7684\u94fe\u63a5\uff0c\u4e0d\u8fc7\u76ee\u524d\u7684\u60c5\u51b5\u662f\u7528\u6237\u5e0c\u671b\u6d4f\u89c8\u5668\u62fc\u547d\u7684\u5c4f\u853d\u5404\u79cd\u5f39\u51fa\u5e7f\u544a\u800c\u540c\u65f6 target=&#8221;_blank&#8221; \u53c8\u662f\u6211\u4eec\u9700\u8981\u7684\u5c5e\u6027\uff0c\u5177\u4f53\u4ee3\u7801\u53ef\u6309\u4ee5\u4e0b\u65b9\u6cd5\u4e66\u5199\u2026\u2026<\/p>\n<p><!--more--><\/p>\n<p>1\u3001\u4e3a\u9700\u8981\u5f39\u51fa\u65b0\u7a97\u53e3\u7684 a \u6807\u8bb0\u6dfb\u52a0 rel=&#8221;external&#8221; \u5c5e\u6027\uff1b<\/p>\n<p>2\u3001\u4e3a\u9875\u9762\u6dfb\u52a0 js \u6216 jQuery \u4ee3\u7801\uff1b<\/p>\n<blockquote><p>a\u3001\u7eaf JavaScript \u4ee3\u7801\uff1a<\/p>\n<pre lang=\"javascript\" line=\"1\">\nfunction externallinks(){\n  if (!document.getElementsByTagName) return;\n  var anchors = document.getElementsByTagName(\"a\");\n  for (var i=0; i<anchors.length; i++){\n    var anchor = anchors[i];\n    if (anchor.getAttribute(\"href\") &#038;&#038; anchor.getAttribute(\"rel\") == \"external\")\n  anchor.target = \"_blank\";\n}\nwindow.onload = externallinks;\n<\/pre>\n<p>b\u3001\u4f7f\u7528 jQuery \u6dfb\u52a0\u4e0b\u9762\u4e00\u53e5\u4ee3\u7801\u5373\u53ef\uff1a<\/p>\n<pre lang=\"javascript\" line=\"1\">\n$(\"a[@rel$='external']\").click(function(){\u00a0this.target = \"_blank\";\u00a0});\n<\/pre>\n<\/blockquote>\n<p>\u53ef\u4ee5\u770b\u51fa\u4f7f\u7528 jQuery \u786e\u5b9e\u662f \u201cWrite Less Do More\u201d \u7684\u975e\u5e38\u65b9\u4fbf\u3002\u5f53\u7136\u5982\u679c\u4f60\u8ddf\u6211\u4e00\u6837\u6b63\u5728\u4f7f\u7528 WordPress \u6216\u901a\u5e38\u60f3\u5077\u61d2\u800c\u4e0d\u613f\u610f\u624b\u5de5\u4e3a\u4e00\u4e9b a \u94fe\u63a5\u6dfb\u52a0 rel \u5c5e\u6027\u7684\u8bdd\uff0c\u53ef\u76f4\u63a5\u6dfb\u52a0\u4e0b\u9762\u7684 jQuery \u4ee3\u7801\uff1a<\/p>\n<blockquote>\n<pre lang=\"javascript\" line=\"1\">$(\".post > .body a\").not(\".more-link\").attr(\"target\",\"_blank\");<\/pre>\n<\/blockquote>\n<p>\u8fd9\u53e5 jQuery \u4ee3\u7801\u662f\u4e3a\u6240\u6709\u535a\u5ba2\u6b63\u6587\u4e2d\u7684 a \u6807\u7b7e\u786c\u6027\u6dfb\u52a0 target=\"_blank\" \u5c5e\u6027\u503c\u800c\u4e0d\u8003\u8651 rel=\"external\" \u5c5e\u6027\uff0c\u5176\u4e2d post \u548c body \u7c7b\u540d\u9700\u8981\u6839\u636e\u4f60\u7684\u4e3b\u9898\u6a21\u677f\u8c03\u6574\uff0c\u56e0\u4e3a\u901a\u5e38\u6b63\u6587\u4e2d\u5f15\u7528\u7684\u94fe\u63a5\u7edd\u5927\u591a\u6570\u90fd\u9700\u8981\u65b0\u5f00\u7a97\u53e3\u6d4f\u89c8\uff0c\u800c\u7f51\u7ad9\u7684\u5176\u4ed6\u5bfc\u822a\u90e8\u5206\u7684\u94fe\u63a5\u901a\u5e38\u4e0d\u9700\u8981\u65b0\u5f00\u7a97\u53e3\u3002<\/p>\n<p>\u8865\u5145\uff1a\u7528\u4e8e a \u6807\u7b7e\u7684 rel \u5c5e\u6027\u8fd8\u6709\u5176\u4ed6\u7684\u4e00\u4e9b\u503c\u5982\uff1anext\u3001previous\u3001chapter\u3001section \u7b49\u7b49\uff0c\u5728 W3C \u4e2d rel \u5c5e\u6027\u4e3b\u8981\u4e3a\u4e86\u8bf4\u660e\u201c\u8be5\u94fe\u63a5\u201d\u4e0e\u201c\u5305\u542b\u8be5\u94fe\u63a5\u7684\u9875\u9762\u201d\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65e2\u7136 W3C \u4e25\u683c\u6807\u51c6\u5c06 target=\u201d_blank\u201d \u5c5e\u6027\u5254\u9664\uff0c\u539f\u56e0\u662f W3C \u8ba4\u4e3a\u672a\u7ecf\u7528\u6237\u540c\u610f\u5c31\u6253\u5f00\u65b0\u7a97 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[20,47,115,85,88,95],"class_list":["post-1085","post","type-post","status-publish","format-standard","hentry","category-tech","tag-code","tag-js","tag-jquery","tag-behavior","tag-w3c","tag-wordpress"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6}},"_links":{"self":[{"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/posts\/1085","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/comments?post=1085"}],"version-history":[{"count":0,"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/posts\/1085\/revisions"}],"wp:attachment":[{"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/media?parent=1085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/categories?post=1085"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/tags?post=1085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}