{"id":221,"date":"2023-02-23T06:31:08","date_gmt":"2023-02-22T22:31:08","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=221"},"modified":"2023-04-30T15:24:10","modified_gmt":"2023-04-30T07:24:10","slug":"jquery-operate-checkbox","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/23\/jquery-operate-checkbox\/","title":{"rendered":"jQuery\u64cd\u4f5ccheckbox"},"content":{"rendered":"<p>jQuery\u64cd\u4f5ccheckbox\u793a\u4f8b\uff1a<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-javascript\">$(&quot;document&quot;).ready(function() {\n  $(&quot;#btn1&quot;).click(function() {\n    $(&quot;[name=&#039;checkbox&#039;]&quot;).attr(&quot;checked&quot;, &#039;true&#039;); \/\/\u5168\u9009\n  })\n  $(&quot;#btn2&quot;).click(function() {\n    $(&quot;[name=&#039;checkbox&#039;]&quot;).removeAttr(&quot;checked&quot;); \/\/\u53d6\u6d88\u5168\u9009\n  })\n  $(&quot;#btn3&quot;).click(function() {\n    $(&quot;[name=&#039;checkbox&#039;]:even&quot;).attr(&quot;checked&quot;, &#039;true&#039;); \/\/\u9009\u4e2d\u6240\u6709\u5947\u6570\n  })\n  $(&quot;#btn4&quot;).click(function() {\n    $(&quot;[name=&#039;checkbox&#039;]&quot;).each(function() { \/\/\u53cd\u9009\n      if($(this).attr(&quot;checked&quot;)) {\n        $(this).removeAttr(&quot;checked&quot;);\n      } else {\n        $(this).attr(&quot;checked&quot;, &#039;true&#039;);\n      }\n    })\n  })\n  $(&quot;#btn5&quot;).click(function() { \/\/\u8f93\u51fa\u9009\u4e2d\u7684\u503c\n    var str = &quot;&quot;;\n    $(&quot;[name=&#039;checkbox&#039;][checked]&quot;).each(function() {\n      str += $(this).val() + &quot;\\r\\n&quot;;\n      \/\/alert($(this).val());\n    })\n    alert(str);\n  })\n})<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>jQuery\u64cd\u4f5ccheckbox\u793a\u4f8b\uff1a $(&quot;document&quot;).ready(funct [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[82],"class_list":["post-221","post","type-post","status-publish","format-standard","hentry","category-frontend-basic","tag-jquery"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=221"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/221\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}