我有一些像这样的HTML
<div id="topContainer">
<div id="level1" style="display:none;"> </div>
<div id="level2" style="display:none;"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我可以检索level1和level2,成功调用show()和hide().但是,有style ="display:none;" 然后调用jQuery("#topContainer").show()执行nada.:(
什么可能是错的?
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()
Run Code Online (Sandbox Code Playgroud)
使用尽可能多的代码更新.
.show()并且.hide()对父母不影响孩子,如果他们被隐藏,他们会隐藏......他们是独立处理的.
但是,.show()如果需要,您也可以呼叫孩子,例如:
jQuery("#topContainer").show().children().show();
Run Code Online (Sandbox Code Playgroud)