{"id":2330,"date":"2024-11-10T15:21:27","date_gmt":"2024-11-10T07:21:27","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2330\/"},"modified":"2024-11-10T15:21:27","modified_gmt":"2024-11-10T07:21:27","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-jquery-%e4%bb%8e-html-%e4%bb%a3%e7%a0%81%e4%b8%ad%e8%8e%b7%e5%8f%96%e4%bf%a1%e6%81%af%e6%a5%bc%e6%96%87%e6%9c%ac%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2330\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 jQuery \u4ece HTML \u4ee3\u7801\u4e2d\u83b7\u53d6\u201c\u4fe1\u606f\u697c\u201d\u6587\u672c\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173071568136030.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 jQuery \u4ece HTML \u4ee3\u7801\u4e2d\u83b7\u53d6\u201c\u4fe1\u606f\u697c\u201d\u6587\u672c\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 jQuery \u4ece HTML \u4ee3\u7801\u4e2d\u83b7\u53d6\u201c\u4fe1\u606f\u697c\u201d\u6587\u672c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u83b7\u53d6\u8282\u70b9<\/strong><\/p>\n<p>\u672c\u6587\u5c06\u63a2\u8ba8\u5982\u4f55\u5728\u63d0\u4f9b\u7684 html \u4ee3\u7801\u4e2d\u4f7f\u7528 jquery \u83b7\u53d6\u7279\u5b9a\u8282\u70b9\u3002<\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u5982\u4f55\u4f7f\u7528 jquery \u4ece html \u4e2d\u83b7\u53d6\u201c\u4fe1\u606f\u697c\u201d\u6587\u672c\uff1f<\/p>\n<p><strong>\u7ed9\u5b9a html\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>&lt;ul&gt;\n  &lt;li&gt;\n    &lt;div&gt;\n      &lt;div&gt;\u4fe1\u606f\u697c&lt;\/div&gt;\n      &lt;img  id=\"tree1\" \/ alt=\"\u5982\u4f55\u4f7f\u7528 jQuery \u4ece HTML \u4ee3\u7801\u4e2d\u83b7\u53d6\u201c\u4fe1\u606f\u697c\u201d\u6587\u672c\uff1f\" &gt;\n      &lt;\/div&gt;\n    &lt;ul id=\"0\"&gt;\n      &lt;li&gt;1000&lt;\/li&gt;\n      &lt;li&gt;2&lt;\/li&gt;\n      &lt;li&gt;3&lt;\/li&gt;\n    &lt;\/ul&gt;\n  &lt;\/li&gt;\n&lt;\/ul&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong><\/p>\n<p>\u8981\u83b7\u53d6\u201c\u4fe1\u606f\u697c\u201d\u6587\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b jquery \u4ee3\u7801\uff1a<\/p>\n<pre>const text = $('#tree1').siblings('div').first().text();\nconsole.log(text);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4e2a\u4ee3\u7801\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<ol>\n<li> <strong>\u9009\u62e9 #tree1 \u5143\u7d20\uff1a<\/strong>\u8fd9\u662f\u6211\u4eec\u611f\u5174\u8da3\u7684 \uc774\ubbf8\uc9c0\u5143\u7d20\u3002<\/li>\n<li> <strong>\u67e5\u627e\u76f8\u90bb\u7684 div \u5143\u7d20\uff1a<\/strong>\u8fd9\u4e2a div \u5143\u7d20\u5305\u542b\u201c\u4fe1\u606f\u697c\u201d\u6587\u672c\u3002<\/li>\n<li> <strong>\u9009\u62e9\u7b2c\u4e00\u4e2a div \u5143\u7d20\uff1a<\/strong>\u6709\u53ef\u80fd\u4f1a\u5b58\u5728\u591a\u4e2a div \u5143\u7d20\uff0c\u4f46\u6211\u4eec\u53ea\u5bf9\u7b2c\u4e00\u4e2a\u611f\u5174\u8da3\u3002<\/li>\n<li> <strong>\u83b7\u53d6\u6587\u672c\uff1a<\/strong>\u4f7f\u7528 .text() \u65b9\u6cd5\u83b7\u53d6 div \u5143\u7d20\u7684\u6587\u672c\u5185\u5bb9\u3002<\/li>\n<\/ol>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u5c06\u8f93\u51fa\u201c\u4fe1\u606f\u697c\u201d\u6587\u672c\u5230\u63a7\u5236\u53f0\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 jQuery \u4ece HTML \u4ee3\u7801\u4e2d\u83b7\u53d6\u201c\u4fe1\u606f\u697c\u201d\u6587\u672c\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>\u83b7\u53d6\u8282\u70b9 \u672c\u6587\u5c06\u63a2\u8ba8\u5982\u4f55\u5728\u63d0\u4f9b\u7684 html \u4ee3\u7801\u4e2d\u4f7f\u7528 jquery \u83b7\u53d6\u7279\u5b9a\u8282\u70b9\u3002 \u95ee\u9898\uff1a \u5982\u4f55\u4f7f\u7528 jquery \u4ece html \u4e2d\u83b7\u53d6\u201c\u4fe1\u606f\u697c\u201d\u6587\u672c\uff1f \u7ed9\u5b9a html\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b &lt;ul&gt; &lt;li&gt; &lt;div&gt; &lt;div&gt;\u4fe1\u606f\u697c&lt;\/div&gt; &lt;img id=&#8221;tree1&#8243; \/ alt=&#8221;\u5982\u4f55\u4f7f\u7528 jQuery \u4ece HTML \u4ee3\u7801\u4e2d\u83b7\u53d6\u201c\u4fe1\u606f\u697c\u201d\u6587\u672c\uff1f&#8221; &gt; &lt;\/div&gt; &lt;ul id=&#8221;0&#8243;&gt; &lt;li&gt;1000&lt;\/li&gt; &lt;li&gt;2&lt;\/li&gt; &lt;li&gt;3&lt;\/li&gt; &lt;\/ul&gt; &lt;\/li&gt; &lt;\/ul&gt; \u767b\u5f55\u540e\u590d\u5236 \u56de\u7b54\uff1a \u8981\u83b7\u53d6\u201c\u4fe1\u606f\u697c\u201d\u6587\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b jquery \u4ee3\u7801\uff1a const text = $(&#8216;#tree1&#8217;).siblings(&#8216;div&#8217;).first().text(); console.log(text); \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u4e2a\u4ee3\u7801\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a \u9009\u62e9 #tree1 \u5143\u7d20\uff1a\u8fd9\u662f\u6211\u4eec\u611f\u5174\u8da3\u7684 \uc774\ubbf8\uc9c0\u5143\u7d20\u3002 \u67e5\u627e\u76f8\u90bb\u7684 div [&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-2330","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2330","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=2330"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2330\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}