{"id":1906,"date":"2024-11-10T13:04:03","date_gmt":"2024-11-10T05:04:03","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1906\/"},"modified":"2024-11-10T13:04:03","modified_gmt":"2024-11-10T05:04:03","slug":"js%e4%b8%89%e5%85%83%e8%a1%a8%e8%be%be%e5%bc%8f%ef%bc%9a%e8%bf%99%e6%ae%b5%e4%bb%a3%e7%a0%81%e7%9a%84%e4%bd%9c%e7%94%a8%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1906\/","title":{"rendered":"JS\u4e09\u5143\u8868\u8fbe\u5f0f\uff1a\u8fd9\u6bb5\u4ee3\u7801\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173061362968109.jpg\" class=\"aligncenter\" title=\"JS\u4e09\u5143\u8868\u8fbe\u5f0f\uff1a\u8fd9\u6bb5\u4ee3\u7801\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" alt=\"JS\u4e09\u5143\u8868\u8fbe\u5f0f\uff1a\u8fd9\u6bb5\u4ee3\u7801\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>js\u4e09\u5143\u8868\u8fbe\u5f0f<\/strong><\/p>\n<p>\u4f60\u5728\u5bfb\u627e\u8fd9\u6bb5\u4ee3\u7801 dt.click(function () { dd.is(&#8220;:hidden&#8221;) ? _show() : _hide(); }); \u7684\u542b\u4e49\uff1f<\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u4f7f\u7528 javascript \u4e09\u5143\u8868\u8fbe\u5f0f\uff0c\u5b83\u662f\u4e00\u79cd\u7b80\u6d01\u7684\u65b9\u5f0f\u6765\u5199 if-else \u8bed\u53e5\u3002<\/p>\n<p>\u4e09\u5143\u8868\u8fbe\u5f0f\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>condition ? trueexpression : falseexpression;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0ccondition \u662f dd.is(&#8220;:hidden&#8221;)\uff0c\u5b83\u68c0\u67e5\u5143\u7d20 dd \u662f\u5426\u9690\u85cf\u3002<\/p>\n<ul>\n<li>\u5982\u679c dd \u662f\u9690\u85cf\u7684\uff08true\uff09\uff0c\u5219 trueexpression\uff08_show()\uff09\u5c06\u6267\u884c\uff0c\u663e\u793a\u5143\u7d20 dd\u3002<\/li>\n<li>\u5982\u679c dd \u4e0d\u662f\u9690\u85cf\u7684\uff08false\uff09\uff0c\u5219 falseexpression\uff08_hide()\uff09\u5c06\u6267\u884c\uff0c\u9690\u85cf\u5143\u7d20 dd\u3002<\/li>\n<\/ul>\n<p>\u56e0\u6b64\uff0c\u8fd9\u6bb5\u4ee3\u7801\u76f8\u5f53\u4e8e\u4ee5\u4e0b if-else \u8bed\u53e5\uff1a<\/p>\n<pre>if (dd.is(\":hidden\")) {\n  _show();\n} else {\n  _hide();\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJS\u4e09\u5143\u8868\u8fbe\u5f0f\uff1a\u8fd9\u6bb5\u4ee3\u7801\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\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>js\u4e09\u5143\u8868\u8fbe\u5f0f \u4f60\u5728\u5bfb\u627e\u8fd9\u6bb5\u4ee3\u7801 dt.click(function () { dd.is(&#8220;:hidden&#8221;) ? _show() : _hide(); }); \u7684\u542b\u4e49\uff1f \u8fd9\u6bb5\u4ee3\u7801\u4f7f\u7528 javascript \u4e09\u5143\u8868\u8fbe\u5f0f\uff0c\u5b83\u662f\u4e00\u79cd\u7b80\u6d01\u7684\u65b9\u5f0f\u6765\u5199 if-else \u8bed\u53e5\u3002 \u4e09\u5143\u8868\u8fbe\u5f0f\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a condition ? trueexpression : falseexpression; \u767b\u5f55\u540e\u590d\u5236 \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0ccondition \u662f dd.is(&#8220;:hidden&#8221;)\uff0c\u5b83\u68c0\u67e5\u5143\u7d20 dd \u662f\u5426\u9690\u85cf\u3002 \u5982\u679c dd \u662f\u9690\u85cf\u7684\uff08true\uff09\uff0c\u5219 trueexpression\uff08_show()\uff09\u5c06\u6267\u884c\uff0c\u663e\u793a\u5143\u7d20 dd\u3002 \u5982\u679c dd \u4e0d\u662f\u9690\u85cf\u7684\uff08false\uff09\uff0c\u5219 falseexpression\uff08_hide()\uff09\u5c06\u6267\u884c\uff0c\u9690\u85cf\u5143\u7d20 dd\u3002 \u56e0\u6b64\uff0c\u8fd9\u6bb5\u4ee3\u7801\u76f8\u5f53\u4e8e\u4ee5\u4e0b if-else \u8bed\u53e5\uff1a if (dd.is(&#8220;:hidden&#8221;)) { _show(); } else { _hide(); } \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0a\u5c31\u662fJS\u4e09\u5143\u8868\u8fbe\u5f0f\uff1a\u8fd9\u6bb5\u4ee3\u7801\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1906","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1906","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=1906"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1906\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}