我有一个 div,我打算像这样隐藏:
$("#bla").hide();
直到一些 jQuery 代码用数据填充它。这似乎打破了“填充代码”。隐藏仍应允许“填充代码”访问 HTML,还是我遗漏了某些内容?
最佳答案
是的,隐藏 div 仍然允许在其中“填充代码”。
来自doc
This is roughly equivalent to calling .css('display', 'none'), except that the value of the display property is saved in jQuery's data cache so that display can later be restored to its initial value.
您所做的基本上只是告诉网页不要显示您的元素。它仍然是 DOM 的一部分。您可以访问它的 html 等。您可以使用 .show
稍后显示
例如:
var elem = $("#bla");
elem.hide();//hides the element
elem.text("Hello World");//sets its inner text to "Hello World"
elem.show(); // "Shows the element again"
这是另一个关于 how hide/show is implemented 的有趣问题
关于jquery - 隐藏div问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15243995/