{"id":1077,"date":"2016-08-05T13:44:59","date_gmt":"2016-08-05T05:44:59","guid":{"rendered":"http:\/\/www.poloo.org\/?p=1077"},"modified":"2016-08-05T14:15:44","modified_gmt":"2016-08-05T06:15:44","slug":"jquery-%e4%b9%8b%e9%80%89%e6%8b%a9%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.poloo.org\/?p=1077","title":{"rendered":"jQuery \u4e4b\u9009\u62e9\u5668"},"content":{"rendered":"<p>jQuery \u7684\u9009\u62e9\u5668\u53ef\u8c13\u4e4b\u5f3a\u5927\u65e0\u6bd4\uff0c\u8fd9\u91cc\u7b80\u5355\u5730\u603b\u7ed3\u4e00\u4e0b\u5e38\u7528\u7684\u5143\u7d20\u67e5\u627e\u65b9\u6cd5<\/p>\n<p>$(&#8220;#myELement&#8221;) \u9009\u62e9id\u503c\u7b49\u4e8emyElement\u7684\u5143\u7d20\uff0cid\u503c\u4e0d\u80fd\u91cd\u590d\u5728\u6587\u6863\u4e2d\u53ea\u80fd\u6709\u4e00\u4e2aid\u503c\u662fmyElement\u6240\u4ee5\u5f97\u5230\u7684\u662f\u552f\u4e00\u7684\u5143\u7d20<br \/>\n$(&#8220;div&#8221;) \u9009\u62e9\u6240\u6709\u7684div\u6807\u7b7e\u5143\u7d20\uff0c\u8fd4\u56dediv\u5143\u7d20\u6570\u7ec4<br \/>\n$(&#8220;.myClass&#8221;) \u9009\u62e9\u4f7f\u7528myClass\u7c7b\u7684css\u7684\u6240\u6709\u5143\u7d20<br \/>\n$(&#8220;*&#8221;) \u9009\u62e9\u6587\u6863\u4e2d\u7684\u6240\u6709\u7684\u5143\u7d20\uff0c\u53ef\u4ee5\u8fd0\u7528\u591a\u79cd\u7684\u9009\u62e9\u65b9\u5f0f\u8fdb\u884c\u8054\u5408\u9009\u62e9\uff1a\u4f8b\u5982$(&#8220;#myELement,div,.myclass&#8221;)<\/p>\n<p>\u5c42\u53e0\u9009\u62e9\u5668\uff1a<br \/>\n$(&#8220;form input&#8221;) \u9009\u62e9\u6240\u6709\u7684form\u5143\u7d20\u4e2d\u7684input\u5143\u7d20<br \/>\n$(&#8220;#main &gt; *&#8221;) \u9009\u62e9id\u503c\u4e3amain\u7684\u6240\u6709\u7684\u5b50\u5143\u7d20<br \/>\n$(&#8220;label + input&#8221;) \u9009\u62e9\u6240\u6709\u7684label\u5143\u7d20\u7684\u4e0b\u4e00\u4e2ainput\u5143\u7d20\u8282\u70b9\uff0c\u7ecf\u6d4b\u8bd5\u9009\u62e9\u5668\u8fd4\u56de\u7684\u662flabel\u6807\u7b7e\u540e\u9762\u76f4\u63a5\u8ddf\u4e00\u4e2ainput\u6807\u7b7e\u7684\u6240\u6709input\u6807\u7b7e\u5143\u7d20<br \/>\n$(&#8220;#prev ~ div&#8221;) \u540c\u80de\u9009\u62e9\u5668\uff0c\u8be5\u9009\u62e9\u5668\u8fd4\u56de\u7684\u4e3aid\u4e3aprev\u7684\u6807\u7b7e\u5143\u7d20\u7684\u6240\u6709\u7684\u5c5e\u4e8e\u540c\u4e00\u4e2a\u7236\u5143\u7d20\u7684div\u6807\u7b7e<\/p>\n<p>\u57fa\u672c\u8fc7\u6ee4\u9009\u62e9\u5668\uff1a<br \/>\n$(&#8220;tr:first&#8221;) \u9009\u62e9\u6240\u6709tr\u5143\u7d20\u7684\u7b2c\u4e00\u4e2a<br \/>\n$(&#8220;tr:last&#8221;) \u9009\u62e9\u6240\u6709tr\u5143\u7d20\u7684\u6700\u540e\u4e00\u4e2a<br \/>\n$(&#8220;input:not(:checked) + span&#8221;)<\/p>\n<p><!--more--><\/p>\n<p>\u8fc7\u6ee4\u6389\uff1achecked\u7684\u9009\u62e9\u5668\u7684\u6240\u6709\u7684input\u5143\u7d20<\/p>\n<p>$(&#8220;tr:even&#8221;) \u9009\u62e9\u6240\u6709\u7684tr\u5143\u7d20\u7684\u7b2c0\uff0c2\uff0c4&#8230; &#8230;\u4e2a\u5143\u7d20\uff08\u6ce8\u610f\uff1a\u56e0\u4e3a\u6240\u9009\u62e9\u7684\u591a\u4e2a\u5143\u7d20\u65f6\u4e3a\u6570\u7ec4\uff0c\u6240\u4ee5\u5e8f\u53f7\u662f\u4ece0\u5f00\u59cb\uff09<\/p>\n<p>$(&#8220;tr:odd&#8221;) \u9009\u62e9\u6240\u6709\u7684tr\u5143\u7d20\u7684\u7b2c1\uff0c3\uff0c5&#8230; &#8230;\u4e2a\u5143\u7d20<br \/>\n$(&#8220;td:eq(2)&#8221;) \u9009\u62e9\u6240\u6709\u7684td\u5143\u7d20\u4e2d\u5e8f\u53f7\u4e3a2\u7684\u90a3\u4e2atd\u5143\u7d20<br \/>\n$(&#8220;td:gt(4)&#8221;) \u9009\u62e9td\u5143\u7d20\u4e2d\u5e8f\u53f7\u5927\u4e8e4\u7684\u6240\u6709td\u5143\u7d20<br \/>\n$(&#8220;td:ll(4)&#8221;) \u9009\u62e9td\u5143\u7d20\u4e2d\u5e8f\u53f7\u5c0f\u4e8e4\u7684\u6240\u6709\u7684td\u5143\u7d20<br \/>\n$(&#8220;:header&#8221;)<br \/>\n$(&#8220;div:animated&#8221;)<br \/>\n\u5185\u5bb9\u8fc7\u6ee4\u9009\u62e9\u5668\uff1a<\/p>\n<p>$(&#8220;div:contains(&#8216;John&#8217;)&#8221;) \u9009\u62e9\u6240\u6709div\u4e2d\u542b\u6709John\u6587\u672c\u7684\u5143\u7d20<br \/>\n$(&#8220;td:empty&#8221;) \u9009\u62e9\u6240\u6709\u7684\u4e3a\u7a7a\uff08\u4e5f\u4e0d\u5305\u62ec\u6587\u672c\u8282\u70b9\uff09\u7684td\u5143\u7d20\u7684\u6570\u7ec4<br \/>\n$(&#8220;div:has(p)&#8221;) \u9009\u62e9\u6240\u6709\u542b\u6709p\u6807\u7b7e\u7684div\u5143\u7d20<br \/>\n$(&#8220;td:parent&#8221;) \u9009\u62e9\u6240\u6709\u7684\u4ee5td\u4e3a\u7236\u8282\u70b9\u7684\u5143\u7d20\u6570\u7ec4<br \/>\n\u53ef\u89c6\u5316\u8fc7\u6ee4\u9009\u62e9\u5668\uff1a<\/p>\n<p>$(&#8220;div:hidden&#8221;) \u9009\u62e9\u6240\u6709\u7684\u88abhidden\u7684div\u5143\u7d20<br \/>\n$(&#8220;div:visible&#8221;) \u9009\u62e9\u6240\u6709\u7684\u53ef\u89c6\u5316\u7684div\u5143\u7d20<br \/>\n\u5c5e\u6027\u8fc7\u6ee4\u9009\u62e9\u5668\uff1a<\/p>\n<p>$(&#8220;div[id]&#8221;) \u9009\u62e9\u6240\u6709\u542b\u6709id\u5c5e\u6027\u7684div\u5143\u7d20<br \/>\n$(&#8220;input[name=&#8217;newsletter&#8217;]&#8221;) \u9009\u62e9\u6240\u6709\u7684name\u5c5e\u6027\u7b49\u4e8e&#8217;newsletter&#8217;\u7684input\u5143\u7d20<\/p>\n<p>$(&#8220;input[name!=&#8217;newsletter&#8217;]&#8221;) \u9009\u62e9\u6240\u6709\u7684name\u5c5e\u6027\u4e0d\u7b49\u4e8e&#8217;newsletter&#8217;\u7684input\u5143\u7d20<\/p>\n<p>$(&#8220;input[name^=&#8217;news&#8217;]&#8221;) \u9009\u62e9\u6240\u6709\u7684name\u5c5e\u6027\u4ee5&#8217;news&#8217;\u5f00\u5934\u7684input\u5143\u7d20<br \/>\n$(&#8220;input[name$=&#8217;news&#8217;]&#8221;) \u9009\u62e9\u6240\u6709\u7684name\u5c5e\u6027\u4ee5&#8217;news&#8217;\u7ed3\u5c3e\u7684input\u5143\u7d20<br \/>\n$(&#8220;input[name*=&#8217;man&#8217;]&#8221;) \u9009\u62e9\u6240\u6709\u7684name\u5c5e\u6027\u5305\u542b&#8217;news&#8217;\u7684input\u5143\u7d20<\/p>\n<p>$(&#8220;input[id][name$=&#8217;man&#8217;]&#8221;) \u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a\u5c5e\u6027\u8fdb\u884c\u8054\u5408\u9009\u62e9\uff0c\u8be5\u9009\u62e9\u5668\u662f\u5f97\u5230\u6240\u6709\u7684\u542b\u6709id\u5c5e\u6027\u5e76\u4e14\u90a3\u4e48\u5c5e\u6027\u4ee5man\u7ed3\u5c3e\u7684\u5143\u7d20<\/p>\n<p>\u5b50\u5143\u7d20\u8fc7\u6ee4\u9009\u62e9\u5668\uff1a<\/p>\n<p>$(&#8220;ul li:nth-child(2)&#8221;),$(&#8220;ul li:nth-child(odd)&#8221;),$(&#8220;ul li:nth-child(3n + 1)&#8221;)<\/p>\n<p>$(&#8220;div span:first-child&#8221;) \u8fd4\u56de\u6240\u6709\u7684div\u5143\u7d20\u7684\u7b2c\u4e00\u4e2a\u5b50\u8282\u70b9\u7684\u6570\u7ec4<br \/>\n$(&#8220;div span:last-child&#8221;) \u8fd4\u56de\u6240\u6709\u7684div\u5143\u7d20\u7684\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u7684\u6570\u7ec4<br \/>\n$(&#8220;div button:only-child&#8221;) \u8fd4\u56de\u6240\u6709\u7684div\u4e2d\u53ea\u6709\u552f\u4e00\u4e00\u4e2a\u5b50\u8282\u70b9\u7684\u6240\u6709\u5b50\u8282\u70b9\u7684\u6570\u7ec4<\/p>\n<p>\u8868\u5355\u5143\u7d20\u9009\u62e9\u5668\uff1a<\/p>\n<p>$(&#8220;:input&#8221;) \u9009\u62e9\u6240\u6709\u7684\u8868\u5355\u8f93\u5165\u5143\u7d20\uff0c\u5305\u62ecinput, textarea, select \u548c button<\/p>\n<p>$(&#8220;:text&#8221;) \u9009\u62e9\u6240\u6709\u7684text input\u5143\u7d20<br \/>\n$(&#8220;:password&#8221;) \u9009\u62e9\u6240\u6709\u7684password input\u5143\u7d20<br \/>\n$(&#8220;:radio&#8221;) \u9009\u62e9\u6240\u6709\u7684radio input\u5143\u7d20<br \/>\n$(&#8220;:checkbox&#8221;) \u9009\u62e9\u6240\u6709\u7684checkbox input\u5143\u7d20<br \/>\n$(&#8220;:submit&#8221;) \u9009\u62e9\u6240\u6709\u7684submit input\u5143\u7d20<br \/>\n$(&#8220;:image&#8221;) \u9009\u62e9\u6240\u6709\u7684image input\u5143\u7d20<br \/>\n$(&#8220;:reset&#8221;) \u9009\u62e9\u6240\u6709\u7684reset input\u5143\u7d20<br \/>\n$(&#8220;:button&#8221;) \u9009\u62e9\u6240\u6709\u7684button input\u5143\u7d20<br \/>\n$(&#8220;:file&#8221;) \u9009\u62e9\u6240\u6709\u7684file input\u5143\u7d20<br \/>\n$(&#8220;:hidden&#8221;) \u9009\u62e9\u6240\u6709\u7c7b\u578b\u4e3ahidden\u7684input\u5143\u7d20\u6216\u8868\u5355\u7684\u9690\u85cf\u57df<\/p>\n<p>\u8868\u5355\u5143\u7d20\u8fc7\u6ee4\u9009\u62e9\u5668\uff1a<\/p>\n<p>$(&#8220;:enabled&#8221;) \u9009\u62e9\u6240\u6709\u7684\u53ef\u64cd\u4f5c\u7684\u8868\u5355\u5143\u7d20<br \/>\n$(&#8220;:disabled&#8221;) \u9009\u62e9\u6240\u6709\u7684\u4e0d\u53ef\u64cd\u4f5c\u7684\u8868\u5355\u5143\u7d20<br \/>\n$(&#8220;:checked&#8221;) \u9009\u62e9\u6240\u6709\u7684\u88abchecked\u7684\u8868\u5355\u5143\u7d20<br \/>\n$(&#8220;select option:selected&#8221;) \u9009\u62e9\u6240\u6709\u7684select \u7684\u5b50\u5143\u7d20\u4e2d\u88abselected\u7684\u5143\u7d20<\/p>\n<p>\u9009\u53d6\u4e00\u4e2a name \u4e3a\u201dS_03_22\u2033\u7684input text\u6846\u7684\u4e0a\u4e00\u4e2atd\u7684text\u503c<br \/>\n$(\u201dinput[@ name =S_03_22]\u201c).parent().prev().text()<\/p>\n<p>\u540d\u5b57\u4ee5\u201dS_\u201d\u5f00\u59cb\uff0c\u5e76\u4e14\u4e0d\u662f\u4ee5\u201d_R\u201d\u7ed3\u5c3e\u7684<br \/>\n$(\u201dinput[@ name ^=&#8217;S_&#8217;]\u201c).not(\u201d[@ name $=&#8217;_R&#8217;]\u201c)<\/p>\n<p>\u4e00\u4e2a\u540d\u4e3a radio_01\u7684radio\u6240\u9009\u7684\u503c<br \/>\n$(\u201dinput[@ name =radio_01][@checked]\u201c).val();<\/p>\n<p>$(&#8220;A B&#8221;) \u67e5\u627eA\u5143\u7d20\u4e0b\u9762\u7684\u6240\u6709\u5b50\u8282\u70b9\uff0c\u5305\u62ec\u975e\u76f4\u63a5\u5b50\u8282\u70b9<br \/>\n$(&#8220;A&gt;B&#8221;) \u67e5\u627eA\u5143\u7d20\u4e0b\u9762\u7684\u76f4\u63a5\u5b50\u8282\u70b9<br \/>\n$(&#8220;A+B&#8221;) \u67e5\u627eA\u5143\u7d20\u540e\u9762\u7684\u5144\u5f1f\u8282\u70b9\uff0c\u5305\u62ec\u975e\u76f4\u63a5\u5b50\u8282\u70b9<br \/>\n$(&#8220;A~B&#8221;) \u67e5\u627eA\u5143\u7d20\u540e\u9762\u7684\u5144\u5f1f\u8282\u70b9\uff0c\u4e0d\u5305\u62ec\u975e\u76f4\u63a5\u5b50\u8282\u70b9<\/p>\n<p>1. $(&#8220;A B&#8221;) \u67e5\u627eA\u5143\u7d20\u4e0b\u9762\u7684\u6240\u6709\u5b50\u8282\u70b9\uff0c\u5305\u62ec\u975e\u76f4\u63a5\u5b50\u8282\u70b9<\/p>\n<p>\u4f8b\u5b50\uff1a\u627e\u5230\u8868\u5355\u4e2d\u6240\u6709\u7684 input \u5143\u7d20<\/p>\n<p>HTML \u4ee3\u7801:<\/p>\n<pre class=\"brush:html\">&lt;form&gt;\r\n&lt;label&gt;Name:&lt;\/label&gt;\r\n&lt;input name=\"name\" \/&gt;\r\n&lt;fieldset&gt;\r\n&lt;label&gt;Newsletter:&lt;\/label&gt;\r\n&lt;input name=\"newsletter\" \/&gt;\r\n&lt;\/fieldset&gt;\r\n&lt;\/form&gt;\r\n&lt;input name=\"none\" \/&gt;\r\n\r\n<\/pre>\n<p>jQuery \u4ee3\u7801:<\/p>\n<pre class=\"brush:js\">\r\n$(\"form input\")\r\n<\/pre>\n<p>\u7ed3\u679c:<\/p>\n<p>[ &lt;input name=&#8221;name&#8221; \/&gt;, &lt;input name=&#8221;newsletter&#8221; \/&gt; ]<\/p>\n<p>2. $(&#8220;A&gt;B&#8221;) \u67e5\u627eA\u5143\u7d20\u4e0b\u9762\u7684\u76f4\u63a5\u5b50\u8282\u70b9<br \/>\n\u4f8b\u5b50\uff1a\u5339\u914d\u8868\u5355\u4e2d\u6240\u6709\u7684\u5b50\u7ea7input\u5143\u7d20\u3002<\/p>\n<p>HTML \u4ee3\u7801:<\/p>\n<pre class=\"brush:html\">&lt;form&gt;\r\n&lt;label&gt;Name:&lt;\/label&gt;\r\n&lt;input name=\"name\" \/&gt;\r\n&lt;fieldset&gt;\r\n&lt;label&gt;Newsletter:&lt;\/label&gt;\r\n&lt;input name=\"newsletter\" \/&gt;\r\n&lt;\/fieldset&gt;\r\n&lt;\/form&gt;\r\n&lt;input name=\"none\" \/&gt;\r\n\r\n<\/pre>\n<p>jQuery \u4ee3\u7801:<\/p>\n<pre class=\"brush:js\">\r\n$(\"form &gt; input\")\r\n<\/pre>\n<p>\u7ed3\u679c:<\/p>\n<p>[ &lt;input name=&#8221;name&#8221; \/&gt; ]<\/p>\n<p>3. $(&#8220;A+B&#8221;) \u67e5\u627eA\u5143\u7d20\u540e\u9762\u7684\u5144\u5f1f\u8282\u70b9\uff0c\u5305\u62ec\u975e\u76f4\u63a5\u5b50\u8282\u70b9<br \/>\n\u4f8b\u5b50\uff1a\u5339\u914d\u6240\u6709\u8ddf\u5728 label \u540e\u9762\u7684 input \u5143\u7d20<\/p>\n<p>HTML \u4ee3\u7801:<\/p>\n<pre class=\"brush:html\">&lt;form&gt;\r\n&lt;label&gt;Name:&lt;\/label&gt;\r\n&lt;input name=\"name\" \/&gt;\r\n&lt;fieldset&gt;\r\n&lt;label&gt;Newsletter:&lt;\/label&gt;\r\n&lt;input name=\"newsletter\" \/&gt;\r\n&lt;\/fieldset&gt;\r\n&lt;\/form&gt;\r\n&lt;input name=\"none\" \/&gt;\r\n\r\n<\/pre>\n<p>jQuery \u4ee3\u7801:<\/p>\n<pre class=\"brush:js\">\r\n$(\"label + input\")\r\n<\/pre>\n<p>\u7ed3\u679c:<\/p>\n<p>[ &lt;input name=&#8221;name&#8221; \/&gt;, &lt;input name=&#8221;newsletter&#8221; \/&gt; ]<\/p>\n<p>4. $(&#8220;A~B&#8221;) \u67e5\u627eA\u5143\u7d20\u540e\u9762\u7684\u5144\u5f1f\u8282\u70b9\uff0c\u4e0d\u5305\u62ec\u975e\u76f4\u63a5\u5b50\u8282\u70b9<br \/>\n\u4f8b\u5b50\uff1a\u627e\u5230\u6240\u6709\u4e0e\u8868\u5355\u540c\u8f88\u7684 input \u5143\u7d20<\/p>\n<p>HTML \u4ee3\u7801:<\/p>\n<pre class=\"brush:html\">&lt;form&gt;\r\n&lt;label&gt;Name:&lt;\/label&gt;\r\n&lt;input name=\"name\" \/&gt;\r\n&lt;fieldset&gt;\r\n&lt;label&gt;Newsletter:&lt;\/label&gt;\r\n&lt;input name=\"newsletter\" \/&gt;\r\n&lt;\/fieldset&gt;\r\n&lt;\/form&gt;\r\n&lt;input name=\"none\" \/&gt;\r\n<\/pre>\n<p>jQuery \u4ee3\u7801:<\/p>\n<pre class=\"brush:js\">\r\n$(\"form ~ input\")\r\n<\/pre>\n<p>\u7ed3\u679c:<\/p>\n<p>[ &lt;input name=&#8221;none&#8221; \/&gt; ]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>jQuery \u7684\u9009\u62e9\u5668\u53ef\u8c13\u4e4b\u5f3a\u5927\u65e0\u6bd4\uff0c\u8fd9\u91cc\u7b80\u5355\u5730\u603b\u7ed3\u4e00\u4e0b\u5e38\u7528\u7684\u5143\u7d20\u67e5&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1078,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[140,23,96,63,43,80,30,146],"class_list":["post-1077","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-Note","tag-html","tag-javascript","tag-jquery","tag-63","tag-43","tag-80","tag-30","tag-146"],"_links":{"self":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/1077","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1077"}],"version-history":[{"count":4,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/1077\/revisions"}],"predecessor-version":[{"id":1082,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/1077\/revisions\/1082"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/media\/1078"}],"wp:attachment":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}