{"id":52845,"date":"2024-12-03T12:33:30","date_gmt":"2024-12-03T04:33:30","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52845\/"},"modified":"2024-12-03T12:33:30","modified_gmt":"2024-12-03T04:33:30","slug":"html-%e7%bd%91%e9%a1%b5%e4%b8%ba%e4%bd%95%e4%b8%8d%e6%96%ad%e5%88%b7%e6%96%b0%ef%bc%9f-javascript-%e5%8f%98%e9%87%8f%e6%8f%90%e5%8d%87%e5%af%bc%e8%87%b4%e7%9a%84%e6%97%a0%e9%99%90%e5%be%aa%e7%8e%af-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52845\/","title":{"rendered":"HTML \u7f51\u9875\u4e3a\u4f55\u4e0d\u65ad\u5237\u65b0\uff1f &#8211; JavaScript \u53d8\u91cf\u63d0\u5347\u5bfc\u81f4\u7684\u65e0\u9650\u5faa\u73af\u95ee\u9898"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>HTML \u7f51\u9875\u4e3a\u4f55\u4e0d\u65ad\u5237\u65b0\uff1f &#8211; JavaScript \u53d8\u91cf\u63d0\u5347\u5bfc\u81f4\u7684\u65e0\u9650\u5faa\u73af\u95ee\u9898 <\/h1>\n<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aHTML \u7f51\u9875\u4e3a\u4f55\u4e0d\u65ad\u5237\u65b0\uff1f &#8211; JavaScript \u53d8\u91cf\u63d0\u5347\u5bfc\u81f4\u7684\u65e0\u9650\u5faa\u73af\u95ee\u9898 \u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241124\/173240680967426e1963867.jpg\" class=\"aligncenter\" title=\"HTML \u7f51\u9875\u4e3a\u4f55\u4e0d\u65ad\u5237\u65b0\uff1f &#8211; JavaScript \u53d8\u91cf\u63d0\u5347\u5bfc\u81f4\u7684\u65e0\u9650\u5faa\u73af\u95ee\u9898\u63d2\u56fe\" alt=\"HTML \u7f51\u9875\u4e3a\u4f55\u4e0d\u65ad\u5237\u65b0\uff1f &#8211; JavaScript \u53d8\u91cf\u63d0\u5347\u5bfc\u81f4\u7684\u65e0\u9650\u5faa\u73af\u95ee\u9898\u63d2\u56fe\" \/><\/p>\n<p><strong>HTML \u7f51\u9875\u4e3a\u4f55\u4e0d\u65ad\u5237\u65b0\uff1f<\/strong><\/p>\n<p>\u521d\u5b66\u8005\u5e38\u4f1a\u9047\u5230\u8fd9\u6837\u7684\u95ee\u9898\uff1a\u4e00\u6bb5\u770b\u4f3c\u7b80\u5355\u7684 HTML \u4ee3\u7801\u6253\u5f00\u7f51\u9875\u540e\u4f1a\u4e0d\u65ad\u5237\u65b0\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n  &lt;head&gt;&lt;\/head&gt;\n  &lt;body&gt;\n    &lt;script&gt;\n      var location = window.location;\n    &lt;\/script&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>\u79fb\u9664\u884c var location = window.location; \u540e\uff0c\u5237\u65b0\u73b0\u8c61\u4fbf\u4f1a\u6d88\u5931\u3002\u90a3\u4e48\uff0c\u95ee\u9898\u51fa\u5728\u54ea\u91cc\u5462\uff1f<\/p>\n<p>\u7b54\u6848\u5728\u4e8e\u53d8\u91cf\u63d0\u5347\u3002\u5728 JavaScript \u4e2d\uff0c\u6700\u9876\u5c42\u7684\u53d8\u91cf\u4f1a\u63d0\u5347\u4e3a\u5168\u5c40\u53d8\u91cf\u5e76\u6302\u8f7d\u5230 globalThis \u5bf9\u8c61\u4e0a\u3002\u5bf9\u4e8e\u6d4f\u89c8\u5668\uff0cglobalThis \u5373 window \u5bf9\u8c61\u3002\u56e0\u6b64\uff0c\u8fd9\u6bb5\u4ee3\u7801\u7b49\u6548\u4e8e\uff1a<\/p>\n<pre>window.location = window.location;<\/pre>\n<p>\u6bcf\u91cd\u65b0\u4e3a location \u8d4b\u503c\u90fd\u4f1a\u89e6\u53d1\u6d4f\u89c8\u5668\u91cd\u65b0\u52a0\u8f7d\u9875\u9762\uff0c\u4f46\u7531\u4e8e\u65b0\u5730\u5740\u4e0e\u65e7\u5730\u5740\u76f8\u540c\uff0c\u5bfc\u81f4\u9875\u9762\u9677\u5165\u65e0\u9650\u5237\u65b0\u5faa\u73af\u3002<\/p>\n<p>\u89e3\u51b3\u529e\u6cd5\u6709\u51e0\u79cd\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 let \u6216 const \u58f0\u660e\u53d8\u91cf\uff0c\u9632\u6b62\u5176\u88ab\u63d0\u5347\u5230\u5168\u5c40\u4f5c\u7528\u57df\uff1a<\/li>\n<\/ul>\n<pre>const location = window.location;<\/pre>\n<ul>\n<li>\u4f7f\u7528 IIFE\uff08\u7acb\u5373\u8c03\u7528\u51fd\u6570\u8868\u8fbe\u5f0f\uff09\u5c06\u53d8\u91cf\u5305\u88f9\u8d77\u6765\uff1a<\/li>\n<\/ul>\n<pre>;(function () {\n    var location = window.location;\n})();<\/pre>\n<ul>\n<li>\u907f\u514d\u4f7f\u7528\u6d4f\u89c8\u5668\u7684\u5185\u7f6e BOM \u5bf9\u8c61\u4f5c\u4e3a\u53d8\u91cf\u540d\u3002<\/li>\n<\/ul>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aHTML \u7f51\u9875\u4e3a\u4f55\u4e0d\u65ad\u5237\u65b0\uff1f &#8211; JavaScript \u53d8\u91cf\u63d0\u5347\u5bfc\u81f4\u7684\u65e0\u9650\u5faa\u73af\u95ee\u9898 \u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   2022\u5e74\u6700\u4f73\u53f0\u5f0f\u7535\u8111\u63a8\u8350\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>HTML \u7f51\u9875\u4e3a\u4f55\u4e0d\u65ad\u5237\u65b0\uff1f &#8211; JavaScript \u53d8\u91cf\u63d0\u5347\u5bfc\u81f4\u7684\u65e0\u9650\u5faa\u73af\u95ee\u9898 \u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aHTML \u7f51\u9875\u4e3a\u4f55\u4e0d\u65ad\u5237\u65b0\uff1f &#8211; JavaScript \u53d8\u91cf\u63d0\u5347\u5bfc\u81f4\u7684\u65e0\u9650\u5faa\u73af\u95ee\u9898 \u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002 HTML \u7f51\u9875\u4e3a\u4f55\u4e0d\u65ad\u5237\u65b0\uff1f \u521d\u5b66\u8005\u5e38\u4f1a\u9047\u5230\u8fd9\u6837\u7684\u95ee\u9898\uff1a\u4e00\u6bb5\u770b\u4f3c\u7b80\u5355\u7684 HTML \u4ee3\u7801\u6253\u5f00\u7f51\u9875\u540e\u4f1a\u4e0d\u65ad\u5237\u65b0\u3002\u4ee3\u7801\u5982\u4e0b\uff1a &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt;&lt;\/head&gt; &lt;body&gt; &lt;script&gt; var location = window.location; &lt;\/script&gt; &lt;\/body&gt; &lt;\/html&gt; \u79fb\u9664\u884c var location = window.location; \u540e\uff0c\u5237\u65b0\u73b0\u8c61\u4fbf\u4f1a\u6d88\u5931\u3002\u90a3\u4e48\uff0c\u95ee\u9898\u51fa\u5728\u54ea\u91cc\u5462\uff1f \u7b54\u6848\u5728\u4e8e\u53d8\u91cf\u63d0\u5347\u3002\u5728 JavaScript \u4e2d\uff0c\u6700\u9876\u5c42\u7684\u53d8\u91cf\u4f1a\u63d0\u5347\u4e3a\u5168\u5c40\u53d8\u91cf\u5e76\u6302\u8f7d\u5230 globalThis \u5bf9\u8c61\u4e0a\u3002\u5bf9\u4e8e\u6d4f\u89c8\u5668\uff0cglobalThis \u5373 window \u5bf9\u8c61\u3002\u56e0\u6b64\uff0c\u8fd9\u6bb5\u4ee3\u7801\u7b49\u6548\u4e8e\uff1a window.location = window.location; \u6bcf\u91cd\u65b0\u4e3a location \u8d4b\u503c\u90fd\u4f1a\u89e6\u53d1\u6d4f\u89c8\u5668\u91cd\u65b0\u52a0\u8f7d\u9875\u9762\uff0c\u4f46\u7531\u4e8e\u65b0\u5730\u5740\u4e0e\u65e7\u5730\u5740\u76f8\u540c\uff0c\u5bfc\u81f4\u9875\u9762\u9677\u5165\u65e0\u9650\u5237\u65b0\u5faa\u73af\u3002 \u89e3\u51b3\u529e\u6cd5\u6709\u51e0\u79cd\uff1a \u4f7f\u7528 let \u6216 const \u58f0\u660e\u53d8\u91cf\uff0c\u9632\u6b62\u5176\u88ab\u63d0\u5347\u5230\u5168\u5c40\u4f5c\u7528\u57df\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-52845","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52845","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=52845"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52845\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}