{"id":3150,"date":"2024-11-10T15:11:35","date_gmt":"2024-11-10T07:11:35","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3150\/"},"modified":"2024-11-10T15:11:35","modified_gmt":"2024-11-10T07:11:35","slug":"js%e5%a6%82%e4%bd%95%e9%9a%90%e8%97%8fdiv","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3150\/","title":{"rendered":"js\u5982\u4f55\u9690\u85cfdiv"},"content":{"rendered":"<blockquote><p>\n  \u5728 javascript \u4e2d\u9690\u85cf div \u5143\u7d20\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528 display \u5c5e\u6027\u5c06\u6837\u5f0f\u8bbe\u7f6e\u4e3a &#8220;none&#8221;\u3002\u4f7f\u7528 visibility \u5c5e\u6027\u5c06\u6837\u5f0f\u8bbe\u7f6e\u4e3a &#8220;hidden&#8221;\u3002\u4f7f\u7528 opacity \u5c5e\u6027\u5c06\u6837\u5f0f\u8bbe\u7f6e\u4e3a 0\u3002\u4f7f\u7528 jquery \u7684 hide() \u65b9\u6cd5\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110805245747713.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u9690\u85cfdiv\u63d2\u56fe\" alt=\"js\u5982\u4f55\u9690\u85cfdiv\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 JavaScript \u4e2d\u9690\u85cf div<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>\u9690\u85cf div \u5143\u7d20\u662f\u524d\u7aef\u5f00\u53d1\u4e2d\u5e38\u89c1\u7684\u9700\u6c42\u3002JavaScript \u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002<\/p>\n<p><strong>\u4f7f\u7528 display \u5c5e\u6027<\/strong><\/p>\n<p>\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 display \u5c5e\u6027\uff1a<\/p>\n<pre>const div = document.getElementById(\"myDiv\");\ndiv.style.display = \"none\";<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5c06\u5176\u8bbe\u7f6e\u4e3a &#8220;none&#8221; \u4f1a\u4f7f div \u5143\u7d20\u4e0d\u53ef\u89c1\u3002<\/p>\n<p><strong>\u4f7f\u7528 visibility \u5c5e\u6027<\/strong><\/p>\n<p>visibility \u5c5e\u6027\u4e5f\u662f\u4e00\u4e2a\u9009\u9879\uff0c\u4f46\u4e0e display \u7565\u6709\u4e0d\u540c\uff1a<\/p>\n<pre>div.style.visibility = \"hidden\";<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5c06 visibility \u8bbe\u7f6e\u4e3a &#8220;hidden&#8221; \u4f1a\u4f7f div \u5143\u7d20\u4e0d\u53ef\u89c1\uff0c\u4f46\u4e0d\u4f1a\u6539\u53d8\u5176\u5927\u5c0f\u6216\u4f4d\u7f6e\u3002<\/p>\n<p><strong>\u4f7f\u7528 opacity \u5c5e\u6027<\/strong><\/p>\n<p>opacity \u5c5e\u6027\u53ef\u4ee5\u4f7f div \u5143\u7d20\u900f\u660e\uff1a<\/p>\n<pre>div.style.opacity = 0;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5c06 opacity \u8bbe\u7f6e\u4e3a 0 \u4f1a\u4f7f\u5176\u5b8c\u5168\u900f\u660e\uff0c\u4ece\u800c\u8fbe\u5230\u9690\u85cf div \u5143\u7d20\u7684\u76ee\u7684\u3002<\/p>\n<p><strong>\u4f7f\u7528 jQuery<\/strong><\/p>\n<p>jQuery \u63d0\u4f9b\u4e86\u4e00\u4e2a\u7b80\u4fbf\u7684\u65b9\u6cd5\u6765\u9690\u85cf div \u5143\u7d20\uff1a<\/p>\n<pre>$(\"#myDiv\").hide();<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u5176\u4ed6\u8003\u8651\u56e0\u7d20<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 hidden \u5c5e\u6027\uff0c\u8fd9\u5c06\u5bfc\u81f4  \u3002 <\/li>\n<li>\u4f7f\u7528 CSS \u7c7b\uff0c\u5176\u4e2d\u5305\u542b display: none;\uff0c\u7136\u540e\u901a\u8fc7 JavaScript \u6dfb\u52a0\u8be5\u7c7b\u3002<\/li>\n<li>\u4f7f\u7528 CSS \u52a8\u753b\u6216\u8fc7\u6e21\u6765\u9010\u6b65\u9690\u85cf div \u5143\u7d20\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 javascript \u4e2d\u9690\u85cf div \u5143\u7d20\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528 display \u5c5e\u6027\u5c06\u6837\u5f0f\u8bbe\u7f6e\u4e3a &#8220;none&#8221;\u3002\u4f7f\u7528 visibility \u5c5e\u6027\u5c06\u6837\u5f0f\u8bbe\u7f6e\u4e3a &#8220;hidden&#8221;\u3002\u4f7f\u7528 opacity \u5c5e\u6027\u5c06\u6837\u5f0f\u8bbe\u7f6e\u4e3a 0\u3002\u4f7f\u7528 jquery \u7684 hide() \u65b9\u6cd5\u3002 \u5982\u4f55\u5728 JavaScript \u4e2d\u9690\u85cf div \u7b80\u4ecb \u9690\u85cf div \u5143\u7d20\u662f\u524d\u7aef\u5f00\u53d1\u4e2d\u5e38\u89c1\u7684\u9700\u6c42\u3002JavaScript \u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002 \u4f7f\u7528 display \u5c5e\u6027 \u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 display \u5c5e\u6027\uff1a const div = document.getElementById(&#8220;myDiv&#8221;); div.style.display = &#8220;none&#8221;; \u767b\u5f55\u540e\u590d\u5236 \u5c06\u5176\u8bbe\u7f6e\u4e3a &#8220;none&#8221; \u4f1a\u4f7f div \u5143\u7d20\u4e0d\u53ef\u89c1\u3002 \u4f7f\u7528 visibility \u5c5e\u6027 visibility \u5c5e\u6027\u4e5f\u662f\u4e00\u4e2a\u9009\u9879\uff0c\u4f46\u4e0e display \u7565\u6709\u4e0d\u540c\uff1a div.style.visibility = [&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-3150","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3150","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=3150"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3150\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}