js控制css display
时间: 2023-10-19 10:31:44 浏览: 84
可以通过JavaScript的style属性来控制CSS中的display属性。具体的语法是使用JavaScript的getElementById方法获取到要控制的元素,然后使用style.display属性来改变元素的显示或隐藏状态。例如,如果要显示一个div容器,可以使用以下代码:
document.getElementById("myDiv").style.display = "block";
如果要隐藏一个div容器,可以使用以下代码:
document.getElementById("myDiv").style.display = "none";
这样就可以通过JavaScript来控制CSS中的display属性了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [JS 控制CSS样式表](https://download.csdn.net/download/weixin_38738511/14821351)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [js控制CSS样式属性语法对照表](https://download.csdn.net/download/weixin_38629206/13669059)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [javascript怎么控制css中的div容器的展示和隐藏](https://blog.csdn.net/m0_68094390/article/details/130668393)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文