当前位置: 代码迷 >> 综合 >> JS 显示隐藏DIV
  详细解决方案

JS 显示隐藏DIV

热度:66   发布时间:2024-02-12 12:00:08.0

JS关闭DIV

HTML

<div id="bar1"> <p onclick="removeElement('bar1')">关闭</p>
</div> 
<div id="bar2"><p onclick="removeElement('bar2')">关闭</p>
</div>

JS

<script type="text/javascript">
function removeElement(id)
{
document.getElementById(id).style.display="none";
}
</script> 

JS显示DIV

<div onclick="showOtherDiv()" style="border:1px solid #fff">点击显示另一个div</div>
<div id="otherDiv" style="display:none;border:1px solid red">点击后显示的div</div><script type="text/javascript">function showOtherDiv(){//获取要显示的div对象var  otherDiv=document.getElementById('otherDiv');//显示otherDiv.style.display="block";
}</script>
  相关解决方案