{"id":32338,"date":"2024-11-25T14:35:03","date_gmt":"2024-11-25T06:35:03","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32338\/"},"modified":"2024-11-25T14:35:03","modified_gmt":"2024-11-25T06:35:03","slug":"rarely-used-jquery-selectors","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32338\/","title":{"rendered":"Rarely Used jQuery Selectors"},"content":{"rendered":"<p>\u9009\u62e9\u5668\u81f3\u5173\u91cd\u8981\u3002\u5927\u591a\u6570 jquery \u65b9\u6cd5\u90fd\u9700\u8981\u67d0\u79cd\u5143\u7d20\u9009\u62e9\u624d\u80fd\u53d1\u6325\u4f5c\u7528\u3002\u4f8b\u5982\uff0c\u5c06 click \u4e8b\u4ef6\u9644\u52a0\u5230\u6309\u94ae\u9700\u8981\u60a8\u9996\u5148\u9009\u62e9\u8be5\u6309\u94ae\u3002 <\/p>\n<p>\u7531\u4e8e\u5e38\u89c1\u7684 jQuery \u9009\u62e9\u5668\u57fa\u4e8e\u73b0\u6709\u7684 CSS \u9009\u62e9\u5668\uff0c\u56e0\u6b64\u60a8\u53ef\u80fd\u975e\u5e38\u719f\u6089\u5b83\u4eec\u3002\u7136\u800c\uff0c\u4e5f\u6709\u4e00\u4e9b\u9009\u62e9\u5668\u6ca1\u6709\u88ab\u5e7f\u6cdb\u4f7f\u7528\u3002\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u5c06\u91cd\u70b9\u5173\u6ce8\u8fd9\u4e9b\u9c9c\u4e3a\u4eba\u77e5\u4f46\u91cd\u8981\u7684\u9009\u62e9\u5668\u3002<\/p>\n<h2>\u6240\u6709\u9009\u62e9\u5668 (*)<\/h2>\n<p>\u8fd9\u4e2a\u9009\u62e9\u5668\u88ab\u6b63\u786e\u5730\u79f0\u4e3a\u901a\u7528\u9009\u62e9\u5668\uff0c\u56e0\u4e3a\u5b83\u9009\u62e9\u6587\u6863\u4e2d\u7684\u6240\u6709\u5143\u7d20\uff0c\u5305\u62ec <\/p>\n<p>, , &lt;script&gt; \u6216 &lt;link&gt; \u6807\u7b7e\u3002\u8fd9\u4e2a\u6f14\u793a\u5e94\u8be5\u53ef\u4ee5\u8bf4\u660e\u6211\u7684\u89c2\u70b9\u3002 &lt;pre class=&#8221;brush:javascript;toolbal:false;&#8221;&gt;$(&#8220;section *&#8221;) \/\/ Selects all descendants $(&#8220;section &gt; *&#8221;) \/\/ Selects all direct descendants $(&#8220;section &gt; * &gt; *&#8221;) \/\/ Selects all second level descendants $(&#8220;section &gt; * &gt; * a&#8221;) \/\/ Selects 3rd level links &lt;p&gt;\u5982\u679c\u4e0e\u5176\u4ed6\u5143\u7d20\u7ed3\u5408\u4f7f\u7528\uff0c\u6b64\u9009\u62e9\u5668\u4f1a\u975e\u5e38\u6162\u3002\u4f46\u662f\uff0c\u8fd9\u5b8c\u5168\u53d6\u51b3\u4e8e\u9009\u62e9\u5668\u7684\u4f7f\u7528\u65b9\u5f0f\u4ee5\u53ca\u5728\u54ea\u4e2a\u6d4f\u89c8\u5668\u4e2d\u6267\u884c\u3002\u5728 Firefox \u4e2d\uff0c$(&#8220;#selector &gt; *&#8221;).find(&#8220;li&#8221;) \u6bd4 $(&#8220;#selector &gt; ul&#8221;).find(&#8220;li&#8221;).\u6709\u8da3\u7684\u662f\uff0cChrome \u6267\u884c $(&#8220;#selector &gt; *&#8221;).find(&#8220;li&#8221;) \u7684\u901f\u5ea6\u7a0d\u5feb\u4e00\u4e9b\u3002\u6240\u6709\u6d4f\u89c8\u5668\u6267\u884c $(&#8220;#selector *&#8221;).find(&#8220;li&#8221;) \u7684\u901f\u5ea6\u90fd\u6bd4 $(&#8220;#selector ul&#8221;).find(&#8220;li&#8221; \u6162)\u3002\u6211\u5efa\u8bae\u60a8\u5728\u4f7f\u7528\u6b64\u9009\u62e9\u5668\u4e4b\u524d\u6bd4\u8f83\u6027\u80fd\u3002 &lt;p&gt; &lt;p&gt;\u8fd9\u91cc\u662f\u4e00\u4e2a\u6bd4\u8f83 all \u9009\u62e9\u5668\u6267\u884c\u901f\u5ea6\u7684\u6f14\u793a\u3002 &lt;h2&gt;\u52a8\u753b\u9009\u62e9\u5668 (:animated) &lt;p&gt;\u60a8\u53ef\u4ee5\u4f7f\u7528 :animated \u9009\u62e9\u5668\u6765\u9009\u62e9\u5728\u6b64\u9009\u62e9\u5668\u8fd0\u884c\u65f6\u52a8\u753b\u4ecd\u5728\u8fdb\u884c\u4e2d\u7684\u6240\u6709\u5143\u7d20\u3002\u552f\u4e00\u7684\u95ee\u9898\u662f\u5b83\u53ea\u4f1a\u9009\u62e9\u4f7f\u7528 jQuery \u8fdb\u884c\u52a8\u753b\u5904\u7406\u7684\u5143\u7d20\u3002\u6b64\u9009\u62e9\u5668\u662f jQuery \u6269\u5c55\uff0c\u4e0d\u4f1a\u53d7\u76ca\u4e8e\u672c\u673a querySelectorAll() \u65b9\u6cd5\u5e26\u6765\u7684\u6027\u80fd\u63d0\u5347\u3002 &lt;p&gt;\u6b64\u5916\uff0c\u60a8\u65e0\u6cd5\u4f7f\u7528 jQuery \u68c0\u6d4b CSS \u52a8\u753b\u3002\u4e0d\u8fc7\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 animationend \u4e8b\u4ef6\u68c0\u6d4b\u52a8\u753b\u4f55\u65f6\u7ed3\u675f\u3002 &lt;p&gt;\u89c2\u770b\u4ee5\u4e0b\u6f14\u793a\u3002 &lt;p&gt;\u5728\u4e0a\u9762\u7684\u6f14\u793a\u4e2d\uff0c\u5728\u6267\u884c $(&#8220;:animated&#8221;).css(&#8220;background&#8221;,&#8221;#6F9&#8243;) \u4e4b\u524d\uff0c\u4ec5\u5bf9\u5947\u6570 div \u5143\u7d20\u8fdb\u884c\u52a8\u753b\u5904\u7406;.\u56e0\u6b64\uff0c\u53ea\u6709\u90a3\u4e9b div \u5143\u7d20\u4f1a\u66f4\u6539\u4e3a\u7eff\u8272\u3002\u4e4b\u540e\uff0c\u6211\u4eec\u5bf9 div \u5143\u7d20\u7684\u5176\u4f59\u90e8\u5206\u8c03\u7528 animate \u51fd\u6570\u3002\u5982\u679c\u60a8\u73b0\u5728\u70b9\u51fb \u6309\u94ae\uff0c\u6240\u6709 div \u5143\u7d20\u90fd\u5e94\u8be5\u53d8\u6210\u7eff\u8272\u3002 &lt;h2&gt;\u5c5e\u6027\u4e0d\u7b49\u4e8e\u9009\u62e9\u5668\uff08[attr!=&#8221;value&#8221;]\uff09 &lt;p&gt;\u901a\u7528\u5c5e\u6027\u9009\u62e9\u5668\u901a\u5e38\u4f1a\u68c0\u6d4b\u5177\u6709\u7ed9\u5b9a\u540d\u79f0\u6216\u503c\u7684\u5c5e\u6027\u662f\u5426\u5b58\u5728\u3002\u53e6\u4e00\u65b9\u9762\uff0c[attr!=&#8221;value&#8221;] \u9009\u62e9\u5668\u5c06\u9009\u62e9\u6240\u6709\u4e0d\u5177\u6709\u6307\u5b9a\u5c5e\u6027\u6216\u8be5\u5c5e\u6027\u5b58\u5728\u4f46\u4e0d\u7b49\u4e8e\u7279\u5b9a\u503c\u7684\u5143\u7d20\u3002\u5b83\u76f8\u5f53\u4e8e :not([attr=&#8221;value&#8221;])\u3002\u4e0e [attr=&#8221;value&#8221;] \u4e0d\u540c\uff0c[attr!=&#8221;value&#8221;] \u4e0d\u662f CSS \u89c4\u8303\u7684\u4e00\u90e8\u5206\u3002\u56e0\u6b64\uff0c\u4f7f\u7528 $(&#8220;css-selector&#8221;).not(&#8220;[attr=&#8217;value&#8217;]&#8221;) \u53ef\u4ee5\u63d0\u9ad8\u73b0\u4ee3\u6d4f\u89c8\u5668\u7684\u6027\u80fd\u3002 &lt;p&gt;\u4e0b\u9762\u7684\u4ee3\u7801\u7247\u6bb5\u5c06 mismatch \u7c7b\u6dfb\u52a0\u5230\u6240\u6709 li \u5143\u7d20\uff0c\u5176 data-category \u5c5e\u6027\u4e0d\u7b49\u4e8e css.\u8fd9\u5728\u8c03\u8bd5\u6216\u4f7f\u7528 JavaScript \u8bbe\u7f6e\u6b63\u786e\u7684\u5c5e\u6027\u503c\u65f6\u5f88\u6709\u5e2e\u52a9\u3002 &lt;pre class=&#8221;brush:javascript;toolbal:false;&#8221;&gt;$(&#8220;li[data-category!=&#8217;css&#8217;]&#8221;).each(function() { $(this).addClass(&#8220;mismatch&#8221;); \/\/ Adds a mismatch class to filtered out selectors. $(&#8220;.mismatch&#8221;).attr(&#8220;data-category&#8221;, attributeValue); \/\/ Set correct attribute value }); &lt;p&gt;\u5728\u6f14\u793a\u4e2d\uff0c\u6211\u68c0\u67e5\u4e86\u4e24\u4e2a\u5217\u8868\u5e76\u66f4\u6b63\u4e86\u5143\u7d20\u7684\u7c7b\u522b\u5c5e\u6027\u7684\u503c\u3002 &lt;h2&gt;\u5305\u542b\u9009\u62e9\u5668\uff08:contains(text)\uff09 &lt;p&gt;\u8be5\u9009\u62e9\u5668\u7528\u4e8e\u9009\u62e9\u5305\u542b\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u6240\u6709\u5143\u7d20\u3002\u5339\u914d\u5b57\u7b26\u4e32\u53ef\u4ee5\u76f4\u63a5\u4f4d\u4e8e\u76f8\u5173\u5143\u7d20\u5185\u90e8\u6216\u5176\u4efb\u4f55\u540e\u4ee3\u5185\u90e8\u3002 &lt;p&gt;\u4e0b\u9762\u7684\u793a\u4f8b\u5e94\u8be5\u53ef\u4ee5\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u7406\u89e3\u8fd9\u4e2a\u9009\u62e9\u5668\u3002\u6211\u4eec\u5c06\u4e3a\u6240\u6709\u51fa\u73b0\u7684\u77ed\u8bed Lorem Ipsum \u6dfb\u52a0\u9ec4\u8272\u80cc\u666f\u3002 &lt;p&gt;\u8ba9\u6211\u4eec\u4ece\u6807\u8bb0\u5f00\u59cb\uff1a &lt;pre class=&#8221;brush:html;toolbal:false;&#8221;&gt;&lt;section&gt; &lt;p&gt;Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&#8217;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. &lt;p&gt;It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of &lt;b&gt;Lorem Ipsum. &lt;a href=&#8221;https:\/\/en.wikipedia.org\/wiki\/Lorem_ipsum&#8221;&gt;Lorem Ipsum Wikipedia Link &lt;section&gt; &lt;p&gt;This &lt;span class=&#8221;small-u&#8221;&gt;lorem ipsum should not be highlighted. &lt;ul&gt; &lt;li&gt;A Lorem Ipsum List &lt;li&gt;More Elements Here &lt;p&gt;\u89c2\u5bdf\u77ed\u8bed Lorem Ipsum \u51fa\u73b0\u5728\u4e03\u4e2a\u4e0d\u540c\u7684\u4f4d\u7f6e\u3002\u6211\u7279\u610f\u5728\u5176\u4e2d\u4e00\u4e2a\u5b9e\u4f8b\u4e2d\u4f7f\u7528\u5c0f\u578b\u5927\u5199\u5b57\u6bcd\uff0c\u4ee5\u8868\u660e\u5339\u914d\u533a\u5206\u5927\u5c0f\u5199\u3002 &lt;p&gt;\u4ee5\u4e0b\u662f\u7a81\u51fa\u663e\u793a\u6240\u6709\u5339\u914d\u9879\u7684 JavaScript \u4ee3\u7801\uff1a &lt;pre class=&#8221;brush:javascript;toolbal:false;&#8221;&gt;$(&#8220;section:contains(&#8216;Lorem Ipsum&#8217;)&#8221;).each(function() { $(this).html( $(this).html().replace(\/Lorem Ipsum\/g, &#8220;&lt;span class=&#8217;match-o&#8217;&gt;Lorem Ipsum&#8221;) ); }); &lt;p&gt;\u5b57\u7b26\u4e32\u5468\u56f4\u7684\u5f15\u53f7\u662f\u53ef\u9009\u7684\u3002\u8fd9\u610f\u5473\u7740 $(&#8220;section:contains(&#8216;Lorem Ipsum&#8217;)&#8221;) \u548c $(&#8220;section:contains(Lorem Ipsum)&#8221;) \u5747\u6709\u6548\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u7247\u6bb5\u4e2d\u3002\u6211\u4ec5\u9488\u5bf9\u90e8\u5206\u5143\u7d20\uff0c\u56e0\u6b64\u5217\u8868\u5143\u7d20\u5185\u7684 Lorem Ipsum \u6587\u672c\u5e94\u4fdd\u6301\u4e0d\u53d8\u3002\u6b64\u5916\uff0c\u7531\u4e8e\u5927\u5c0f\u5199\u4e0d\u5339\u914d\uff0c\u7b2c\u4e8c\u4e2a section \u5143\u7d20\u5185\u7684\u6587\u672c\u4e5f\u4e0d\u5e94\u7a81\u51fa\u663e\u793a\u3002\u6b63\u5982\u60a8\u5728\u6b64\u6f14\u793a\u4e2d\u6240\u770b\u5230\u7684\uff0c\u8fd9\u6b63\u662f\u6240\u53d1\u751f\u7684\u60c5\u51b5\u3002 &lt;h2&gt;\u6709\u9009\u62e9\u5668 (:has(selector)) &lt;p&gt;\u6b64\u9009\u62e9\u5668\u5c06\u9009\u62e9\u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u4e0e\u7ed9\u5b9a\u9009\u62e9\u5668\u5339\u914d\u7684\u5143\u7d20\u7684\u6240\u6709\u5143\u7d20\u3002\u9700\u8981\u5339\u914d\u7684\u9009\u62e9\u5668\u4e0d\u5fc5\u662f\u76f4\u63a5\u5b50\u7ea7\u3002 :has() \u4e0d\u662f CSS \u89c4\u8303\u7684\u4e00\u90e8\u5206\u3002\u5728\u73b0\u4ee3\u6d4f\u89c8\u5668\u4e2d\uff0c\u60a8\u5e94\u8be5\u4f7f\u7528 $(&#8220;pure-css-selector&#8221;).has(selector) \u800c\u4e0d\u662f $(&#8220;pure-css-selector:has(\u9009\u62e9\u5668)&#8221;) \u4ee5\u63d0\u9ad8\u6027\u80fd\u3002 &lt;p&gt;\u6b64\u9009\u62e9\u5668\u7684\u4e00\u4e2a\u53ef\u80fd\u7684\u5e94\u7528\u662f\u64cd\u4f5c\u5176\u4e2d\u5305\u542b\u7279\u5b9a\u5143\u7d20\u7684\u5143\u7d20\u3002\u5728\u6211\u4eec\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u5c06\u66f4\u6539\u5185\u90e8\u5305\u542b\u94fe\u63a5\u7684\u6240\u6709\u5217\u8868\u5143\u7d20\u7684\u989c\u8272\u3002 &lt;p&gt;\u8fd9\u662f\u6f14\u793a\u7684\u6807\u8bb0\uff1a &lt;pre class=&#8221;brush:html;toolbal:false;&#8221;&gt;&lt;ul&gt; &lt;li&gt;Pellentesque &lt;a href=&#8221;dummy.html&#8221;&gt;habitant morbi tristique senectus. &lt;li&gt;Pellentesque habitant morbi tristique senectus. (&#8230; more list elements here &#8230;) &lt;li&gt;Pellentesque habitant morbi tristique senectus. &lt;li&gt;Pellentesque &lt;a href=&#8221;dummy.html&#8221;&gt;habitant morbi tristique senectus. &lt;p&gt;\u4ee5\u4e0b\u662f\u66f4\u6539\u5217\u8868\u5143\u7d20\u989c\u8272\u7684 JavaScript \u4ee3\u7801\uff1a &lt;pre class=&#8221;brush:javascript;toolbal:false;&#8221;&gt;$(&#8220;li:has(a)&#8221;).each(function(index) { $(this).css(&#8220;color&#8221;, &#8220;crimson&#8221;); }); &lt;p&gt;\u8fd9\u6bb5\u4ee3\u7801\u80cc\u540e\u7684\u903b\u8f91\u975e\u5e38\u7b80\u5355\u3002\u6211\u5faa\u73af\u904d\u5386\u6240\u6709\u5305\u542b\u94fe\u63a5\u7684\u5217\u8868\u5143\u7d20\u5e76\u5c06\u5176\u989c\u8272\u8bbe\u7f6e\u4e3a\u6df1\u7ea2\u8272\u3002\u60a8\u8fd8\u53ef\u4ee5\u64cd\u4f5c\u5217\u8868\u5143\u7d20\u5185\u7684\u6587\u672c\u6216\u5c06\u5b83\u4eec\u4ece DOM \u4e2d\u5220\u9664\u3002\u6211\u786e\u4fe1\u8fd9\u4e2a\u9009\u62e9\u5668\u53ef\u4ee5\u7528\u5728\u5f88\u591a\u5176\u4ed6\u60c5\u51b5\u4e0b\u3002\u5728 CodePen \u4e0a\u67e5\u770b\u6b64\u4ee3\u7801\u7684\u5b9e\u65f6\u7248\u672c\u3002 &lt;h2&gt;\u57fa\u4e8e\u7d22\u5f15\u7684\u9009\u62e9\u5668 &lt;p&gt;\u9664\u4e86\u50cf :nth-child() \u8fd9\u6837\u7684 CSS \u9009\u62e9\u5668\u4e4b\u5916\uff0cjQuery \u4e5f\u6709\u81ea\u5df1\u7684\u4e00\u7ec4\u57fa\u4e8e\u7d22\u5f15\u7684\u9009\u62e9\u5668\u3002\u8fd9\u4e9b\u9009\u62e9\u5668\u662f :eq(index)\u3001:lt(index) \u548c :gt(index)\u3002\u4e0e\u57fa\u4e8e CSS \u7684\u9009\u62e9\u5668\u4e0d\u540c\uff0c\u8fd9\u4e9b\u9009\u62e9\u5668\u4f7f\u7528\u4ece\u96f6\u5f00\u59cb\u7684\u7d22\u5f15\u3002\u8fd9\u610f\u5473\u7740 :nth-child(1) \u5c06\u9009\u62e9\u7b2c\u4e00\u4e2a\u5b50\u7ea7\uff0c\u800c :eq(1) \u5c06\u9009\u62e9\u7b2c\u4e8c\u4e2a\u5b50\u7ea7\u3002\u8981\u9009\u62e9\u7b2c\u4e00\u4e2a\u5b69\u5b50\uff0c\u60a8\u5fc5\u987b\u4f7f\u7528 :eq(0)\u3002 &lt;p&gt;\u8fd9\u4e9b\u9009\u62e9\u5668\u4e5f\u53ef\u4ee5\u63a5\u53d7\u8d1f\u503c\u3002\u5f53\u6307\u5b9a\u8d1f\u503c\u65f6\uff0c\u5c06\u4ece\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5f00\u59cb\u5411\u540e\u8ba1\u6570\u3002 &lt;p&gt;:lt(index) \u9009\u62e9\u7d22\u5f15\u5c0f\u4e8e\u6307\u5b9a\u503c\u7684\u6240\u6709\u5143\u7d20\u3002\u8981\u9009\u62e9\u524d\u4e09\u4e2a\u5143\u7d20\uff0c\u60a8\u5c06\u4f7f\u7528 :lt(3)\u3002\u8fd9\u662f\u56e0\u4e3a\u524d\u4e09\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u503c\u5206\u522b\u4e3a 0\u30011 \u548c 2\u3002\u4f7f\u7528\u8d1f\u7d22\u5f15\u5c06\u9009\u62e9\u5411\u540e\u8ba1\u6570\u540e\u5230\u8fbe\u7684\u5143\u7d20\u4e4b\u524d\u7684\u6240\u6709\u503c\u3002\u540c\u6837\uff0c:gt(index) \u9009\u62e9\u7d22\u5f15\u5927\u4e8e\u6307\u5b9a\u503c\u7684\u6240\u6709\u5143\u7d20\u3002 &lt;pre class=&#8221;brush:html;toolbal:false;&#8221;&gt;:lt(4) \/\/ Selects first four elements :lt(-4) \/\/ Selects all elements besides last 4 :gt(4) \/\/ Selects all elements besides first 5 :gt(-4) \/\/ Selects last three elements :gt(-1) \/\/ Selects Nothing :eq(4) \/\/ Selects fifth element :eq(-4) \/\/ Selects fourth element from last &lt;p&gt;\u5c1d\u8bd5\u5355\u51fb\u6f14\u793a\u4e2d\u7684\u5404\u4e2a\u6309\u94ae\u4ee5\u66f4\u597d\u5730\u4e86\u89e3\u7d22\u5f15\u9009\u62e9\u5668\u3002 &lt;h2&gt;\u8868\u5355\u9009\u62e9\u5668 &lt;p&gt;jQuery \u5b9a\u4e49\u4e86\u8bb8\u591a\u9009\u62e9\u5668\uff0c\u4ee5\u4fbf\u8f7b\u677e\u9009\u62e9\u8868\u5355\u5143\u7d20\u3002\u4f8b\u5982\uff0c :button \u9009\u62e9\u5668\u5c06\u9009\u62e9\u6240\u6709\u6309\u94ae\u5143\u7d20\u4ee5\u53ca\u6309\u94ae\u7c7b\u578b\u7684\u5143\u7d20\u3002\u540c\u6837\uff0c :checkbox \u5c06\u9009\u62e9\u6240\u6709\u7c7b\u578b\u4e3a checkbox \u7684\u8f93\u5165\u5143\u7d20\u3002\u51e0\u4e4e\u6240\u6709\u8f93\u5165\u5143\u7d20\u90fd\u5b9a\u4e49\u4e86\u9009\u62e9\u5668\u3002\u8003\u8651\u4e0b\u9762\u7684\u8868\u683c\uff1a &lt;pre class=&#8221;brush:html;toolbal:false;&#8221;&gt;&lt;form action=&#8221;#&#8221; method=&#8221;post&#8221;&gt; &lt;div&gt; &lt;label for=&#8221;name&#8221;&gt;Text Input &lt;br&gt; &lt;input type=&#8221;text&#8221; name=&#8221;name&#8221; \/&gt; &lt;input type=&#8221;text&#8221; name=&#8221;name&#8221; \/&gt; &lt;hr&gt; &lt;div&gt; &lt;label for=&#8221;checkbox&#8221;&gt;Checkbox: &lt;input type=&#8221;checkbox&#8221; name=&#8221;checkbox&#8221; \/&gt; &lt;input type=&#8221;checkbox&#8221; name=&#8221;checkbox&#8221; \/&gt; &lt;input type=&#8221;checkbox&#8221; name=&#8221;checkbox&#8221; \/&gt; &lt;input type=&#8221;checkbox&#8221; name=&#8221;checkbox&#8221; \/&gt; &lt;p&gt;\u6211\u5728\u8fd9\u91cc\u521b\u5efa\u4e86\u4e24\u4e2a\u6587\u672c\u5143\u7d20\u548c\u56db\u4e2a\u590d\u9009\u6846\u3002\u8be5\u8868\u5355\u975e\u5e38\u57fa\u672c\uff0c\u4f46\u5b83\u5e94\u8be5\u8ba9\u60a8\u4e86\u89e3\u8868\u5355\u9009\u62e9\u5668\u7684\u5de5\u4f5c\u539f\u7406\u3002\u6211\u4eec\u5c06\u4f7f\u7528 :text \u9009\u62e9\u5668\u8ba1\u7b97\u6587\u672c\u5143\u7d20\u7684\u6570\u91cf\uff0c\u5e76\u66f4\u65b0\u7b2c\u4e00\u4e2a\u6587\u672c\u8f93\u5165\u4e2d\u7684\u6587\u672c\u3002 &lt;pre class=&#8221;brush:javascript;toolbal:false;&#8221;&gt;var textCount = $(&#8220;:text&#8221;).length; $(&#8220;.text-elements&#8221;).text(&#8216;Text Inputs : &#8216; + textCount); $(&#8220;:text&#8221;).eq(0).val(&#8216;Added programatically!&#8217;); &lt;p&gt;\u6211\u4f7f\u7528 :text \u9009\u62e9\u6240\u6709\u6587\u672c\u8f93\u5165\uff0c\u7136\u540e\u4f7f\u7528 length \u65b9\u6cd5\u6765\u8ba1\u7b97\u5b83\u4eec\u7684\u6570\u91cf\u3002\u5728\u7b2c\u4e09\u6761\u8bed\u53e5\u4e2d\uff0c\u6211\u4f7f\u7528\u524d\u9762\u8ba8\u8bba\u7684 :eq() \u9009\u62e9\u5668\u6765\u8bbf\u95ee\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u7136\u540e\u8bbe\u7f6e\u5176\u503c\u3002 &lt;p&gt;\u8bf7\u8bb0\u4f4f\uff0c\u4ece jQuery 1.5.2 \u5f00\u59cb\uff0c\u5bf9\u4e8e\u672a\u6307\u5b9a\u4efb\u4f55 type \u5c5e\u6027\u7684\u5143\u7d20\uff0c:text \u8fd4\u56de true\u3002 &lt;p&gt;\u770b\u770b\u6f14\u793a\u3002 &lt;h2&gt;\u6807\u5934\u9009\u62e9\u5668 (:header) &lt;p&gt;\u5982\u679c\u60a8\u60f3\u9009\u62e9\u7f51\u9875\u4e0a\u7684\u6240\u6709\u6807\u9898\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u7b80\u77ed\u7684 $(&#8220;:header&#8221;) \u7248\u672c\uff0c\u800c\u4e0d\u662f\u8be6\u7ec6\u7684 $ (&#8220;h1 h2 h3 h4 h5 h6&#8221;) \u9009\u62e9\u5668\u3002\u6b64\u9009\u62e9\u5668\u4e0d\u662f CSS \u89c4\u8303\u7684\u4e00\u90e8\u5206\u3002\u56e0\u6b64\uff0c\u9996\u5148\u4f7f\u7528\u7eaf CSS \u9009\u62e9\u5668\uff0c\u7136\u540e\u4f7f\u7528 .filter(&#8220;:header&#8221;) \u53ef\u4ee5\u83b7\u5f97\u66f4\u597d\u7684\u6027\u80fd\u3002 &lt;p&gt;\u4f8b\u5982\uff0c\u5047\u8bbe\u7f51\u9875\u4e0a\u6709\u4e00\u4e2a article \u5143\u7d20\uff0c\u5e76\u4e14\u5b83\u5177\u6709\u4e09\u4e2a\u4e0d\u540c\u7684\u6807\u9898\u3002\u73b0\u5728\uff0c\u4e3a\u4e86\u7b80\u6d01\u8d77\u89c1\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 $(&#8220;article :header&#8221;) \u800c\u4e0d\u662f $(&#8220;article h1,article h2,article h3&#8221;)\u3002\u4e3a\u4e86\u4f7f\u5176\u66f4\u5feb\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 $(&#8220;article&#8221;).filter(&#8220;:header&#8221;)\u3002\u8fd9\u6837\u60a8\u5c31\u53ef\u4ee5\u4e24\u5168\u5176\u7f8e\u3002 &lt;p&gt;\u8981\u5bf9\u6240\u6709\u6807\u9898\u5143\u7d20\u8fdb\u884c\u7f16\u53f7\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u3002 &lt;pre class=&#8221;brush:javascript;toolbal:false;&#8221;&gt;$(&#8220;article :header&#8221;).each(function(index) { $(this).text((index + 1) + &#8220;: &#8221; + $(this).text()); \/\/ Adds numbers to Headings }); &lt;p&gt;\u5c1d\u8bd5\u4e00\u4e0b\u968f\u9644\u7684\u6f14\u793a\u3002 &lt;h2&gt;\u6700\u7ec8\u60f3\u6cd5 &lt;p&gt;\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u8ba8\u8bba\u4e86\u4f7f\u7528 jQuery \u65f6\u53ef\u80fd\u9047\u5230\u7684\u4e0d\u5e38\u89c1\u9009\u62e9\u5668\u3002\u867d\u7136\u5927\u591a\u6570\u9009\u62e9\u5668\u90fd\u6709\u53ef\u4f9b\u60a8\u4f7f\u7528\u7684\u66ff\u4ee3\u65b9\u6848\uff0c\u4f46\u4e86\u89e3\u8fd9\u4e9b\u9009\u62e9\u5668\u7684\u5b58\u5728\u4ecd\u7136\u662f\u4ef6\u597d\u4e8b\u3002 &lt;p&gt;\u6211\u5e0c\u671b\u60a8\u5728\u672c\u6559\u7a0b\u4e2d\u5b66\u5230\u4e86\u4e00\u4e9b\u65b0\u4e1c\u897f\u3002\u5982\u679c\u60a8\u6709\u4efb\u4f55\u95ee\u9898\u6216\u5efa\u8bae\uff0c\u8bf7\u8bc4\u8bba\u3002&lt;\/script&gt; <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fRarely Used jQuery Selectors\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>\u9009\u62e9\u5668\u81f3\u5173\u91cd\u8981\u3002\u5927\u591a\u6570 jquery \u65b9\u6cd5\u90fd\u9700\u8981\u67d0\u79cd\u5143\u7d20\u9009\u62e9\u624d\u80fd\u53d1\u6325\u4f5c\u7528\u3002\u4f8b\u5982\uff0c\u5c06 click \u4e8b\u4ef6\u9644\u52a0\u5230\u6309\u94ae\u9700\u8981\u60a8\u9996\u5148\u9009\u62e9\u8be5\u6309\u94ae\u3002 \u7531\u4e8e\u5e38\u89c1\u7684 jQuery \u9009\u62e9\u5668\u57fa\u4e8e\u73b0\u6709\u7684 CSS \u9009\u62e9\u5668\uff0c\u56e0\u6b64\u60a8\u53ef\u80fd\u975e\u5e38\u719f\u6089\u5b83\u4eec\u3002\u7136\u800c\uff0c\u4e5f\u6709\u4e00\u4e9b\u9009\u62e9\u5668\u6ca1\u6709\u88ab\u5e7f\u6cdb\u4f7f\u7528\u3002\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u5c06\u91cd\u70b9\u5173\u6ce8\u8fd9\u4e9b\u9c9c\u4e3a\u4eba\u77e5\u4f46\u91cd\u8981\u7684\u9009\u62e9\u5668\u3002 \u6240\u6709\u9009\u62e9\u5668 (*) \u8fd9\u4e2a\u9009\u62e9\u5668\u88ab\u6b63\u786e\u5730\u79f0\u4e3a\u901a\u7528\u9009\u62e9\u5668\uff0c\u56e0\u4e3a\u5b83\u9009\u62e9\u6587\u6863\u4e2d\u7684\u6240\u6709\u5143\u7d20\uff0c\u5305\u62ec , , &lt;script&gt; \u6216 &lt;link&gt; \u6807\u7b7e\u3002\u8fd9\u4e2a\u6f14\u793a\u5e94\u8be5\u53ef\u4ee5\u8bf4\u660e\u6211\u7684\u89c2\u70b9\u3002 &lt;pre class=&#8221;brush:javascript;toolbal:false;&#8221;&gt;$(&#8220;section *&#8221;) \/\/ Selects all descendants $(&#8220;section &gt; *&#8221;) \/\/ Selects all direct descendants $(&#8220;section &gt; * &gt; *&#8221;) \/\/ Selects all second level descendants $(&#8220;section &gt; * &gt; * a&#8221;) \/\/ Selects 3rd level [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-32338","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32338","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=32338"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32338\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}