{"id":1777,"date":"2024-11-10T17:06:35","date_gmt":"2024-11-10T09:06:35","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1777\/"},"modified":"2024-11-10T17:06:35","modified_gmt":"2024-11-10T09:06:35","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-javascript-%e7%ae%80%e4%be%bf%e5%9c%b0%e4%b8%ba%e4%bb%a3%e7%a0%81%e6%b7%bb%e5%8a%a0%e8%a1%8c%e5%8f%b7%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1777\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 JavaScript \u7b80\u4fbf\u5730\u4e3a\u4ee3\u7801\u6dfb\u52a0\u884c\u53f7\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173055802476959.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 JavaScript \u7b80\u4fbf\u5730\u4e3a\u4ee3\u7801\u6dfb\u52a0\u884c\u53f7\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 JavaScript \u7b80\u4fbf\u5730\u4e3a\u4ee3\u7801\u6dfb\u52a0\u884c\u53f7\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u7528 javascript \u6700\u7b80\u4fbf\u5730\u7ed9\u4ee3\u7801\u52a0\u884c\u53f7<\/strong><\/p>\n<p>\u7ed9\u4ee3\u7801\u52a0\u884c\u53f7\u5bf9\u4e8e\u4ee3\u7801\u5ba1\u67e5\u3001\u8c03\u8bd5\u548c\u5176\u4ed6\u4efb\u52a1\u6765\u8bf4\u975e\u5e38\u6709\u7528\u3002\u867d\u7136\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\uff0c\u4f46 JavaScript \u63d0\u4f9b\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u53ef\u4ee5\u8ba9\u8fd9\u4e2a\u8fc7\u7a0b\u53d8\u5f97\u8f7b\u800c\u6613\u4e3e\u3002<\/p>\n<p><strong>\u4f7f\u7528 xmp \u6807\u7b7e<\/strong><\/p>\n<p>\u4f7f\u7528 xmp \u6807\u7b7e\u662f\u7ed9\u4ee3\u7801\u52a0\u884c\u53f7\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u4f46\u662f\uff0cxmp \u5df2\u88ab\u6807\u8bb0\u4e3a\u5e9f\u5f03\uff0c\u4e0d\u5efa\u8bae\u5728\u65b0\u7684\u9879\u76ee\u4e2d\u4f7f\u7528\u3002<\/p>\n<p><strong>\u4f7f\u7528 pre \u6807\u7b7e<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u867d\u7136\u53ef\u4ee5\u7528 pre \u6807\u7b7e\u4ee3\u66ff xmp\uff0c\u4f46\u5b83\u9700\u8981\u5bf9\u4ee3\u7801\u8fdb\u884c\u8f6c\u4e49\uff0c\u4f7f\u5f97\u5b83\u53d8\u5f97\u66f4\u52a0\u590d\u6742\u3002<\/p>\n<p><strong>\u4f7f\u7528 JavaScript<\/strong><\/p>\n<p>\u76f8\u6bd4\u4e4b\u4e0b\uff0cJavaScript \u63d0\u4f9b\u4e86\u4e00\u79cd\u4f18\u96c5\u4e14\u7b80\u5355\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u4e0d\u9700\u8981\u5bf9\u4ee3\u7801\u8fdb\u884c\u4efb\u4f55\u4fee\u6539\u3002\u53ea\u9700\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6bb5\uff1a<\/p>\n<pre>var $code = document.getElementById('code');\n`&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n    &lt;meta charset=\"UTF-8\"&gt;\n    &lt;title&gt;\u884c\u53f7&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;p&gt;\u6d4b\u8bd5\u9875\u9762&lt;\/p&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;`.split('\n').forEach((text, index) =&gt; {\n  var $line = document.createElement('p');\n  $line.dataset.lineNumber = index + 1;\n  $line.innerText = text;\n  $code.appendChild($line);\n});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u5c06\u6b64\u4ee3\u7801\u6bb5\u6dfb\u52a0\u5230 HTML \u6587\u6863\u4e2d\uff0c\u5b83\u5c06\u83b7\u53d6\u5177\u6709 ID \u4e3a &#8220;code&#8221; \u7684\u5143\u7d20\u5e76\u4e3a\u5176\u6dfb\u52a0\u884c\u53f7\uff1a<\/p>\n<pre>&lt;div id=\"code\" style=\"font-size:12px\"&gt;&lt;\/div&gt;\n&lt;script&gt;\n  \/\/ \u4ee3\u7801\u6bb5\u5728\u6b64\u5904\n&lt;\/script&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>CSS \u6837\u5f0f<\/strong><\/p>\n<p>\u8981\u5bf9\u884c\u53f7\u8fdb\u884c\u6837\u5f0f\u5316\uff0c\u53ef\u4ee5\u5728\u6837\u5f0f\u8868\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>* {margin: 0; padding: 0;}\n#code p::before {content: attr(data-line-number);min-width: 50px;text-align: right;display: inline-block;padding: 0 5px;color: #ccc;}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 JavaScript \u7b80\u4fbf\u5730\u4e3a\u4ee3\u7801\u6dfb\u52a0\u884c\u53f7\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7528 javascript \u6700\u7b80\u4fbf\u5730\u7ed9\u4ee3\u7801\u52a0\u884c\u53f7 \u7ed9\u4ee3\u7801\u52a0\u884c\u53f7\u5bf9\u4e8e\u4ee3\u7801\u5ba1\u67e5\u3001\u8c03\u8bd5\u548c\u5176\u4ed6\u4efb\u52a1\u6765\u8bf4\u975e\u5e38\u6709\u7528\u3002\u867d\u7136\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\uff0c\u4f46 JavaScript \u63d0\u4f9b\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u53ef\u4ee5\u8ba9\u8fd9\u4e2a\u8fc7\u7a0b\u53d8\u5f97\u8f7b\u800c\u6613\u4e3e\u3002 \u4f7f\u7528 xmp \u6807\u7b7e \u4f7f\u7528 xmp \u6807\u7b7e\u662f\u7ed9\u4ee3\u7801\u52a0\u884c\u53f7\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u4f46\u662f\uff0cxmp \u5df2\u88ab\u6807\u8bb0\u4e3a\u5e9f\u5f03\uff0c\u4e0d\u5efa\u8bae\u5728\u65b0\u7684\u9879\u76ee\u4e2d\u4f7f\u7528\u3002 \u4f7f\u7528 pre \u6807\u7b7e \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u867d\u7136\u53ef\u4ee5\u7528 pre \u6807\u7b7e\u4ee3\u66ff xmp\uff0c\u4f46\u5b83\u9700\u8981\u5bf9\u4ee3\u7801\u8fdb\u884c\u8f6c\u4e49\uff0c\u4f7f\u5f97\u5b83\u53d8\u5f97\u66f4\u52a0\u590d\u6742\u3002 \u4f7f\u7528 JavaScript \u76f8\u6bd4\u4e4b\u4e0b\uff0cJavaScript \u63d0\u4f9b\u4e86\u4e00\u79cd\u4f18\u96c5\u4e14\u7b80\u5355\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u4e0d\u9700\u8981\u5bf9\u4ee3\u7801\u8fdb\u884c\u4efb\u4f55\u4fee\u6539\u3002\u53ea\u9700\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6bb5\uff1a var $code = document.getElementById(&#8216;code&#8217;); `&lt;!DOCTYPE html&gt; &lt;html lang=&#8221;en&#8221;&gt; &lt;head&gt; &lt;meta charset=&#8221;UTF-8&#8243;&gt; &lt;title&gt;\u884c\u53f7&lt;\/title&gt; &lt;\/head&gt; &lt;body&gt; &lt;p&gt;\u6d4b\u8bd5\u9875\u9762&lt;\/p&gt; &lt;\/body&gt; &lt;\/html&gt;`.split(&#8216; &#8216;).forEach((text, index) =&gt; { var $line = document.createElement(&#8216;p&#8217;); $line.dataset.lineNumber = index + 1; [&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-1777","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1777","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=1777"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1777\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}