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