{"id":51,"date":"2024-04-10T22:47:12","date_gmt":"2024-04-10T14:47:12","guid":{"rendered":"https:\/\/www.weigot.com\/?p=51"},"modified":"2024-04-10T22:47:12","modified_gmt":"2024-04-10T14:47:12","slug":"javascript-%e6%9d%a5%e6%98%be%e7%a4%ba%e6%9f%90%e4%ba%9b%e5%86%85%e5%ae%b9%ef%bc%8c%e5%b9%b6%e7%a6%81%e6%ad%a2%e6%90%9c%e7%b4%a2%e5%bc%95%e6%93%8e%e6%9f%a5%e7%9c%8b%e8%af%a5%e5%86%85%e5%ae%b9","status":"publish","type":"post","link":"http:\/\/www.weigot.com\/index.php\/2024\/04\/10\/javascript-%e6%9d%a5%e6%98%be%e7%a4%ba%e6%9f%90%e4%ba%9b%e5%86%85%e5%ae%b9%ef%bc%8c%e5%b9%b6%e7%a6%81%e6%ad%a2%e6%90%9c%e7%b4%a2%e5%bc%95%e6%93%8e%e6%9f%a5%e7%9c%8b%e8%af%a5%e5%86%85%e5%ae%b9\/","title":{"rendered":"JavaScript \u6765\u663e\u793a\u67d0\u4e9b\u5185\u5bb9\uff0c\u5e76\u7981\u6b62\u641c\u7d22\u5f15\u64ce\u67e5\u770b\u8be5\u5185\u5bb9"},"content":{"rendered":"\n<p>\u5982\u679c\u4f60\u60f3\u5728\u7f51\u9875\u4e2d\u4f7f\u7528 JavaScript \u6765\u663e\u793a\u67d0\u4e9b\u5185\u5bb9\uff0c\u5e76\u7981\u6b62\u641c\u7d22\u5f15\u64ce\u67e5\u770b\u8be5\u5185\u5bb9\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<p>\u52a8\u6001\u751f\u6210\u5185\u5bb9\uff1a\u4f7f\u7528 JavaScript \u52a8\u6001\u751f\u6210\u5185\u5bb9\u53ef\u4ee5\u4f7f\u641c\u7d22\u5f15\u64ce\u65e0\u6cd5\u5728\u521d\u59cb\u52a0\u8f7d\u65f6\u83b7\u5f97\u8be5\u5185\u5bb9\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u7279\u5b9a\u6761\u4ef6\u6216\u4e8b\u4ef6\uff0c\u5728\u9875\u9762\u52a0\u8f7d\u5b8c\u6210\u540e\u4f7f\u7528 JavaScript \u6765\u751f\u6210\u6240\u9700\u7684\u5185\u5bb9\uff0c\u5e76\u5c06\u5176\u63d2\u5165\u5230\u7f51\u9875\u4e2d\u3002\u8fd9\u6837\uff0c\u641c\u7d22\u5f15\u64ce\u5728\u521d\u59cb\u6293\u53d6\u9875\u9762\u65f6\u65e0\u6cd5\u770b\u5230\u8be5\u5185\u5bb9\u3002<\/p>\n\n\n\n<p>\u4f7f\u7528 AJAX \u52a0\u8f7d\u5185\u5bb9\uff1a\u4f7f\u7528 AJAX \u8bf7\u6c42\u52a0\u8f7d\u5185\u5bb9\u65f6\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u9009\u62e9\u662f\u5426\u5c06\u8be5\u5185\u5bb9\u6807\u8bb0\u4e3a\u4e0d\u53ef\u7d22\u5f15\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e\u901a\u8fc7 AJAX \u8bf7\u6c42\u52a0\u8f7d\u7684\u5185\u5bb9\uff0c\u4f60\u53ef\u4ee5\u5728\u8bf7\u6c42\u7684\u54cd\u5e94\u4e2d\u5305\u542bX-Robots-Tag\u6807\u5934\uff0c\u5e76\u5c06\u5176\u8bbe\u7f6e\u4e3anoindex\uff0c\u6307\u793a\u641c\u7d22\u5f15\u64ce\u4e0d\u8981\u7d22\u5f15\u8be5\u5185\u5bb9\u3002<\/p>\n\n\n\n<p>javascript<br>\u590d\u5236<br>var xhr = new XMLHttpRequest();<br>xhr.onreadystatechange = function() {<br>if (xhr.readyState === 4 &amp;&amp; xhr.status === 200) {<br>var content = xhr.responseText;<br>\/\/ \u5c06\u5185\u5bb9\u63d2\u5165\u5230\u7f51\u9875\u4e2d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u6807\u8bb0\u4e3a\u4e0d\u53ef\u7d22\u5f15\nxhr.getResponseHeader(\"X-Robots-Tag\") = \"noindex\";<\/code><\/pre>\n\n\n\n<p>}<br>};<br>xhr.open(&#8220;GET&#8221;, &#8220;content-url&#8221;, true);<br>xhr.send();<br>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u901a\u8fc7 AJAX \u8bf7\u6c42\u83b7\u53d6\u5185\u5bb9\uff0c\u5e76\u5c06\u5185\u5bb9\u63d2\u5165\u5230\u7f51\u9875\u4e2d\u3002\u540c\u65f6\uff0c\u8bbe\u7f6e\u54cd\u5e94\u5934\u4e2d\u7684X-Robots-Tag\u4e3anoindex\uff0c\u4ee5\u6307\u793a\u641c\u7d22\u5f15\u64ce\u4e0d\u8981\u7d22\u5f15\u8be5\u5185\u5bb9\u3002<\/p>\n\n\n\n<p>\u8bf7\u6ce8\u610f\uff0c\u5c3d\u7ba1\u4e0a\u8ff0\u65b9\u6cd5\u53ef\u4ee5\u963b\u6b62\u5927\u591a\u6570\u641c\u7d22\u5f15\u64ce\u7d22\u5f15\u5185\u5bb9\uff0c\u4f46\u5e76\u4e0d\u80fd\u4fdd\u8bc1\u6240\u6709\u641c\u7d22\u5f15\u64ce\u90fd\u4f1a\u5b8c\u5168\u9075\u5b88\u8fd9\u4e9b\u6307\u793a\u3002\u4e00\u4e9b\u641c\u7d22\u5f15\u64ce\u53ef\u80fd\u4f1a\u5ffd\u7565\u6216\u4e0d\u7406\u89e3\u8fd9\u4e9b\u8bbe\u7f6e\uff0c\u56e0\u6b64\u5b83\u4eec\u4ecd\u7136\u53ef\u80fd\u7d22\u5f15\u4f60\u5e0c\u671b\u9690\u85cf\u7684\u5185\u5bb9\u3002\u5982\u679c\u4f60\u9700\u8981\u66f4\u4e25\u683c\u7684\u5185\u5bb9\u9690\u85cf\u548c\u641c\u7d22\u5f15\u64ce\u4f18\u5316\u63a7\u5236\uff0c\u53ef\u80fd\u9700\u8981\u8fdb\u4e00\u6b65\u7814\u7a76\u548c\u91c7\u7528\u5176\u4ed6\u65b9\u6cd5\uff0c\u4f8b\u5982\u4f7f\u7528\u767b\u5f55\u9a8c\u8bc1\u6216\u4f7f\u7528robots.txt\u6587\u4ef6\u6765\u9650\u5236\u641c\u7d22\u5f15\u64ce\u8bbf\u95ee\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u4f60\u60f3\u5728\u7f51\u9875\u4e2d\u4f7f\u7528 JavaScript \u6765\u663e\u793a\u5360\u4f4d\u7b26\u5185\u5bb9\uff0c\u5e76\u4e14\u4e0d\u5e0c\u671b\u641c\u7d22\u5f15\u64ce\u67e5\u770b\u8be5\u5185\u5bb9\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528 JavaScript \u52a8\u6001\u751f\u6210\u5360\u4f4d\u7b26\u5143\u7d20\uff0c\u5e76\u5728\u641c\u7d22\u5f15\u64ce\u7d22\u5f15\u7f51\u9875\u65f6\u9690\u85cf\u6216\u66ff\u6362\u8fd9\u4e9b\u5143\u7d20\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u4e00\u79cd\u5b9e\u73b0\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>HTML \u7ed3\u6784\uff1a\u5728 HTML \u4e2d\uff0c\u4f60\u53ef\u4ee5\u4e3a\u5360\u4f4d\u7b26\u5185\u5bb9\u7559\u51fa\u4e00\u4e2a\u5bb9\u5668\u5143\u7d20\uff0c\u4f8b\u5982\u4e00\u4e2a\u7a7a\u7684 <code>&lt;div><\/code> \u5143\u7d20\uff0c\u4f7f\u7528\u4e00\u4e2a\u7279\u5b9a\u7684 ID \u6216\u7c7b\u540d\u8fdb\u884c\u6807\u8bc6\u3002<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   &lt;div id=\"placeholder\"&gt;&lt;\/div&gt;<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li>JavaScript \u52a8\u6001\u751f\u6210\u5360\u4f4d\u7b26\u5185\u5bb9\uff1a\u5728 JavaScript \u4e2d\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u52a8\u6001\u751f\u6210\u5360\u4f4d\u7b26\u5185\u5bb9\uff0c\u5e76\u5c06\u5176\u63d2\u5165\u5230\u5360\u4f4d\u7b26\u5bb9\u5668\u5143\u7d20\u4e2d\u3002<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   var placeholderElement = document.getElementById(\"placeholder\"); \/\/ \u83b7\u53d6\u5360\u4f4d\u7b26\u5bb9\u5668\u5143\u7d20\n\n   var placeholderContent = \"This is the placeholder content.\"; \/\/ \u5360\u4f4d\u7b26\u5185\u5bb9\n\n   placeholderElement.textContent = placeholderContent; \/\/ \u5c06\u5360\u4f4d\u7b26\u5185\u5bb9\u8d4b\u503c\u7ed9\u5bb9\u5668\u5143\u7d20\u7684\u6587\u672c\u5185\u5bb9<\/code><\/pre>\n\n\n\n<p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 JavaScript \u83b7\u53d6\u5360\u4f4d\u7b26\u5bb9\u5668\u5143\u7d20\uff0c\u5e76\u5c06\u6240\u9700\u7684\u5360\u4f4d\u7b26\u5185\u5bb9\u8d4b\u503c\u7ed9\u5bb9\u5668\u5143\u7d20\u7684\u6587\u672c\u5185\u5bb9\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li>\u9690\u85cf\u6216\u66ff\u6362\u5360\u4f4d\u7b26\u5185\u5bb9\uff1a\u4e3a\u4e86\u5728\u641c\u7d22\u5f15\u64ce\u7d22\u5f15\u7f51\u9875\u65f6\u9690\u85cf\u6216\u66ff\u6362\u5360\u4f4d\u7b26\u5185\u5bb9\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>CSS \u9690\u85cf\uff1a\u4f7f\u7528 CSS \u6837\u5f0f\u5c06\u5360\u4f4d\u7b26\u5bb9\u5668\u5143\u7d20\u9690\u85cf\uff0c\u4f8b\u5982\u5c06\u5176\u8bbe\u7f6e\u4e3a\u4e0d\u53ef\u89c1\u6216\u8bbe\u7f6e <code>display: none;<\/code>\u3002 <code>#placeholder { display: none; }<\/code> \u8fd9\u6837\uff0c\u5728\u641c\u7d22\u5f15\u64ce\u7d22\u5f15\u7f51\u9875\u65f6\uff0c\u5360\u4f4d\u7b26\u5bb9\u5668\u5143\u7d20\u5c06\u88ab\u9690\u85cf\uff0c\u641c\u7d22\u5f15\u64ce\u65e0\u6cd5\u770b\u5230\u5176\u4e2d\u7684\u5185\u5bb9\u3002<\/li>\n\n\n\n<li>\u66ff\u6362\u5185\u5bb9\uff1a\u5728\u7f51\u9875\u88ab\u52a0\u8f7d\u548c\u6e32\u67d3\u65f6\uff0c\u4f7f\u7528 JavaScript \u5c06\u5360\u4f4d\u7b26\u5bb9\u5668\u5143\u7d20\u66ff\u6362\u4e3a\u5b9e\u9645\u5185\u5bb9\u3002\u8fd9\u6837\uff0c\u5728\u641c\u7d22\u5f15\u64ce\u7d22\u5f15\u7f51\u9875\u65f6\uff0c\u4f1a\u770b\u5230\u5b9e\u9645\u5185\u5bb9\u800c\u4e0d\u662f\u5360\u4f4d\u7b26\u3002 <code>var actualContent = \"This is the actual content.\"; \/\/ \u5b9e\u9645\u5185\u5bb9 placeholderElement.textContent = actualContent; \/\/ \u5c06\u5b9e\u9645\u5185\u5bb9\u8d4b\u503c\u7ed9\u5bb9\u5668\u5143\u7d20\u7684\u6587\u672c\u5185\u5bb9<\/code> \u8fd9\u6bb5\u4ee3\u7801\u4f1a\u5c06\u5b9e\u9645\u5185\u5bb9\u66ff\u6362\u5360\u4f4d\u7b26\u5bb9\u5668\u5143\u7d20\u4e2d\u7684\u5185\u5bb9\u3002\u5728\u641c\u7d22\u5f15\u64ce\u7d22\u5f15\u7f51\u9875\u65f6\uff0c\u5c06\u770b\u5230\u5b9e\u9645\u5185\u5bb9\u800c\u4e0d\u662f\u5360\u4f4d\u7b26\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 JavaScript \u52a8\u6001\u751f\u6210\u5360\u4f4d\u7b26\u5185\u5bb9\uff0c\u5e76\u5728\u641c\u7d22\u5f15\u64ce\u7d22\u5f15\u7f51\u9875\u65f6\u9690\u85cf\u6216\u66ff\u6362\u8be5\u5185\u5bb9\uff0c\u4ece\u800c\u5b9e\u73b0\u9690\u85cf\u5360\u4f4d\u7b26\u5185\u5bb9\u7684\u6548\u679c\u3002\u8bf7\u6ce8\u610f\uff0c\u641c\u7d22\u5f15\u64ce\u4e0d\u4e00\u5b9a\u4f1a\u5b8c\u5168\u9075\u5b88\u8fd9\u4e9b\u9690\u85cf\u6216\u66ff\u6362\u7b56\u7565\uff0c\u56e0\u6b64\u65e0\u6cd5\u4fdd\u8bc1\u5185\u5bb9\u4e0d\u88ab\u7d22\u5f15\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u4f60\u60f3\u5728\u7f51\u9875\u4e2d\u4f7f\u7528 JavaScript \u6765\u663e\u793a\u67d0\u4e9b\u5185\u5bb9\uff0c\u5e76\u7981\u6b62\u641c\u7d22\u5f15\u64ce\u67e5\u770b\u8be5\u5185\u5bb9\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a \u52a8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-51","post","type-post","status-publish","format-standard","hentry","category-suibianjilu"],"_links":{"self":[{"href":"http:\/\/www.weigot.com\/index.php\/wp-json\/wp\/v2\/posts\/51","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.weigot.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weigot.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weigot.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weigot.com\/index.php\/wp-json\/wp\/v2\/comments?post=51"}],"version-history":[{"count":1,"href":"http:\/\/www.weigot.com\/index.php\/wp-json\/wp\/v2\/posts\/51\/revisions"}],"predecessor-version":[{"id":52,"href":"http:\/\/www.weigot.com\/index.php\/wp-json\/wp\/v2\/posts\/51\/revisions\/52"}],"wp:attachment":[{"href":"http:\/\/www.weigot.com\/index.php\/wp-json\/wp\/v2\/media?parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weigot.com\/index.php\/wp-json\/wp\/v2\/categories?post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weigot.com\/index.php\/wp-json\/wp\/v2\/tags?post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}