Jquery Hide() 和 Show() 不工作——非常沮丧

标签 jquery hide show

我有一些像这样的 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/

相关文章:

javascript - 带 onclick 的 INPUT 类型图像不适用于 JS

html - 我用于隐藏元素的 CSS 媒体查询在我的 HTC ONE M8 上不起作用

带有presentModalViewController的ios uidatepicker

jQuery - 以不同的时间间隔显示/隐藏 div

javascript - 当文本框值与另一个 div 的内容相同时显示 div

Javascript fadeIn() 过渡

jquery - 如何在设置高度后获取图像的宽度

javascript - 如何通过单击文本框jquery使表格可见

html - 是否可以通过 CSS 隐藏链接的标题?

react-native - Detox:如何测试多行 TextInput