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>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM