JS 显示隐藏DIV

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>
posted @ 2017-10-11 16:18  caobiin  阅读(24604)  评论(0编辑  收藏  举报