{"id":48635,"date":"2024-12-02T13:16:32","date_gmt":"2024-12-02T05:16:32","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48635\/"},"modified":"2024-12-02T13:16:32","modified_gmt":"2024-12-02T05:16:32","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-javascript-%e4%bb%a3%e7%a0%81%e6%9b%bf%e6%8d%a2-html-%e4%b8%ad%e6%89%80%e6%9c%89%e6%96%87%e6%9c%ac%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48635\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 JavaScript \u4ee3\u7801\u66ff\u6362 HTML \u4e2d\u6240\u6709\u6587\u672c\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 JavaScript \u4ee3\u7801\u66ff\u6362 HTML \u4e2d\u6240\u6709\u6587\u672c\uff1f<\/h1>\n<p>\u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u662f\u7ed3\u5408\u6211\u4e4b\u524d\u9762\u8bd5\u7684\u5404\u79cd\u7ecf\u5386\u548c\u5b9e\u6218\u5f00\u53d1\u4e2d\u9047\u5230\u7684\u95ee\u9898\u89e3\u51b3\u7ecf\u9a8c\u6574\u7406\u7684\uff0c\u5e0c\u671b\u8fd9\u7bc7\u300a\u5982\u4f55\u4f7f\u7528 JavaScript \u4ee3\u7801\u66ff\u6362 HTML \u4e2d\u6240\u6709\u6587\u672c\uff1f\u300b\u5bf9\u4f60\u6709\u5f88\u5927\u5e2e\u52a9\uff01\u6b22\u8fce\u6536\u85cf\uff0c\u5206\u4eab\u7ed9\u66f4\u591a\u7684\u9700\u8981\u7684\u670b\u53cb\u5b66\u4e60~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241029\/1730176765672066fd63863.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 JavaScript \u4ee3\u7801\u66ff\u6362 HTML \u4e2d\u6240\u6709\u6587\u672c\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 JavaScript \u4ee3\u7801\u66ff\u6362 HTML \u4e2d\u6240\u6709\u6587\u672c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u66ff\u6362 html \u4e2d\u6587\u672c\u7684\u5229\u5668<\/strong><\/p>\n<p>\u5728 web \u5f00\u53d1\u4e2d\uff0c\u6709\u65f6\u6211\u4eec\u9700\u8981\u66ff\u6362 html \u4e2d\u7684\u6240\u6709\u6587\u672c\uff0c\u4f8b\u5982\u8c37\u6b4c\u7ffb\u8bd1\u9875\u9762\uff0c\u4ec5\u8f6c\u6362\u6587\u672c\u5185\u5bb9\u800c\u4fdd\u6301 html \u7ed3\u6784\u4e0d\u53d8\u3002<\/p>\n<p>\u4e3a\u4e86\u6ee1\u8db3\u8fd9\u4e00\u9700\u6c42\uff0c\u6709\u5fc5\u8981\u4e86\u89e3\u4ee5\u4e0b\u4ee3\u7801\u7247\u6bb5\uff1a<\/p>\n<pre>array.from($$('*')).filter(v=&amp;gt;array.from(v.childnodes).filter(v=&amp;gt;v.nodename== \"#text\" &amp;amp;&amp;amp; v.textcontent.trim())?.length)<\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\uff1a<\/p>\n<ul>\n<li>\u83b7\u53d6\u9875\u9762\u4e2d\u6240\u6709\u5143\u7d20\uff08array.from($(&#8216;*&#8217;))\uff09\u3002<\/li>\n<li>\u7b5b\u9009\u51fa\u5177\u6709\u6587\u672c\u5185\u5bb9\u7684\u5143\u7d20\uff08filter(v=&gt;array.from(v.childnodes).filter(v=&gt;v.nodename== &#8220;#text&#8221; &amp;&amp; v.textcontent.trim())?.length)\uff09\u3002<\/li>\n<\/ul>\n<p>\u6709\u4e86\u8fd9\u4e9b\u5143\u7d20\u540e\uff0c\u5c31\u53ef\u4ee5\u904d\u5386\u5b83\u4eec\u5e76\u6309\u7167\u9700\u8981\u66ff\u6362\u5185\u5bb9\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre>const nodes = Array.from($$('*')).filter(v=&amp;gt;Array.from(v.childNodes).filter(v=&amp;gt;v.nodeName== \"#text\" &amp;amp;&amp;amp; v.textContent.trim())?.length);\nfor (const node of nodes) {\n  node.textContent = node.textContent.replace(\/foo\/g, 'bar');\n}<\/pre>\n<p>\u8fd9\u5c06\u67e5\u627e\u6240\u6709\u5305\u542b\u6587\u672c\u7684\u5143\u7d20\uff0c\u5e76\u5c06\u5176\u4e2d\u7684 &#8220;foo&#8221; \u66ff\u6362\u4e3a &#8220;bar&#8221;\u3002<\/p>\n<p>\u901a\u8fc7\u5229\u7528\u6b64\u4ee3\u7801\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u66ff\u6362 html \u4e2d\u7684\u6240\u6709\u6587\u672c\uff0c\u5e76\u5b9e\u73b0\u7c7b\u4f3c\u8c37\u6b4c\u7ffb\u8bd1\u9875\u9762\u7684\u6548\u679c\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u5982\u4f55\u4f7f\u7528 JavaScript \u4ee3\u7801\u66ff\u6362 HTML \u4e2d\u6240\u6709\u6587\u672c\uff1f\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u7c73\u4e91\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 JavaScript \u4ee3\u7801\u66ff\u6362 HTML \u4e2d\u6240\u6709\u6587\u672c\uff1f \u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u662f\u7ed3\u5408\u6211\u4e4b\u524d\u9762\u8bd5\u7684\u5404\u79cd\u7ecf\u5386\u548c\u5b9e\u6218\u5f00\u53d1\u4e2d\u9047\u5230\u7684\u95ee\u9898\u89e3\u51b3\u7ecf\u9a8c\u6574\u7406\u7684\uff0c\u5e0c\u671b\u8fd9\u7bc7\u300a\u5982\u4f55\u4f7f\u7528 JavaScript \u4ee3\u7801\u66ff\u6362 HTML \u4e2d\u6240\u6709\u6587\u672c\uff1f\u300b\u5bf9\u4f60\u6709\u5f88\u5927\u5e2e\u52a9\uff01\u6b22\u8fce\u6536\u85cf\uff0c\u5206\u4eab\u7ed9\u66f4\u591a\u7684\u9700\u8981\u7684\u670b\u53cb\u5b66\u4e60~ \u66ff\u6362 html \u4e2d\u6587\u672c\u7684\u5229\u5668 \u5728 web \u5f00\u53d1\u4e2d\uff0c\u6709\u65f6\u6211\u4eec\u9700\u8981\u66ff\u6362 html \u4e2d\u7684\u6240\u6709\u6587\u672c\uff0c\u4f8b\u5982\u8c37\u6b4c\u7ffb\u8bd1\u9875\u9762\uff0c\u4ec5\u8f6c\u6362\u6587\u672c\u5185\u5bb9\u800c\u4fdd\u6301 html \u7ed3\u6784\u4e0d\u53d8\u3002 \u4e3a\u4e86\u6ee1\u8db3\u8fd9\u4e00\u9700\u6c42\uff0c\u6709\u5fc5\u8981\u4e86\u89e3\u4ee5\u4e0b\u4ee3\u7801\u7247\u6bb5\uff1a array.from($$(&#8216;*&#8217;)).filter(v=&amp;gt;array.from(v.childnodes).filter(v=&amp;gt;v.nodename== &#8220;#text&#8221; &amp;amp;&amp;amp; v.textcontent.trim())?.length) \u8fd9\u6bb5\u4ee3\u7801\uff1a \u83b7\u53d6\u9875\u9762\u4e2d\u6240\u6709\u5143\u7d20\uff08array.from($(&#8216;*&#8217;))\uff09\u3002 \u7b5b\u9009\u51fa\u5177\u6709\u6587\u672c\u5185\u5bb9\u7684\u5143\u7d20\uff08filter(v=&gt;array.from(v.childnodes).filter(v=&gt;v.nodename== &#8220;#text&#8221; &amp;&amp; v.textcontent.trim())?.length)\uff09\u3002 \u6709\u4e86\u8fd9\u4e9b\u5143\u7d20\u540e\uff0c\u5c31\u53ef\u4ee5\u904d\u5386\u5b83\u4eec\u5e76\u6309\u7167\u9700\u8981\u66ff\u6362\u5185\u5bb9\u3002 \u4ee5\u4e0b\u662f\u793a\u4f8b\u4ee3\u7801\uff1a const nodes = Array.from($$(&#8216;*&#8217;)).filter(v=&amp;gt;Array.from(v.childNodes).filter(v=&amp;gt;v.nodeName== &#8220;#text&#8221; &amp;amp;&amp;amp; v.textContent.trim())?.length); for (const node of nodes) { node.textContent = node.textContent.replace(\/foo\/g, &#8216;bar&#8217;); } \u8fd9\u5c06\u67e5\u627e\u6240\u6709\u5305\u542b\u6587\u672c\u7684\u5143\u7d20\uff0c\u5e76\u5c06\u5176\u4e2d\u7684 &#8220;foo&#8221; \u66ff\u6362\u4e3a &#8220;bar&#8221;\u3002 [&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-48635","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48635","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=48635"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48635\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}