我有一些像这样的 HTML
<div id="topContainer">
<div id="level1" style="display:none;"> </div>
<div id="level2" style="display:none;"></div>
</div>
我可以检索 level1 和 level2,并成功调用它们的 show() 和 hide() 。但是,有 style="display:none;"然后调用 jQuery("#topContainer").show() 也没什么作用。 :(
可能出了什么问题?
下面是JS
//LOGIC HERE THAT SHOWS LEVEL1 and LEVEL2 based on business logic
//If neither div is shown (got a variable set to false, it set to true each time
//the business logic shows the div
//if variable is still false, then the below line runs
jQuery("#topContainer").hide()
更新了尽可能多的代码。
最佳答案
.show()
和 .hide()
对 parent 的影响不会影响 child ,如果他们被隐藏,他们就会保持隐藏......他们被独立处理。
不过,您可以调用.show()
如果需要的话,也可以针对 child ,例如:
jQuery("#topContainer").show().children().show();
关于Jquery Hide() 和 Show() 不工作——非常沮丧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4083131/