js彈窗 js彈出DIV,並使整個頁面背景變暗


1.首先寫一個遮罩層div,然后再寫一個彈窗的div

<!-- 遮罩層 -->
<div id="cover" style="background: #000; position: absolute; left: 0px; top: 0px; width: 100%;  filter: alpha(opacity=30); opacity: 0.3; display: none; z-index: 2 ">
    
</div>

<!-- 彈窗 -->
<div id="showdiv" style="width: 80%; margin: 0 auto; height: 9.5rem; border: 1px solid #999; display: none; position: absolute; top: 40%; left: 10%; z-index: 3; background: #fff">
    <!-- 標題 -->
    <div style="background: #F8F7F7; width: 100%; height: 2rem; font-size: 0.65rem; line-height: 2rem; border: 1px solid #999; text-align: center;" >
        提示
    </div>
    <!-- 內容 -->
    <div style="text-indent: 50px; height: 4rem; font-size: 0.5rem; padding: 0.5rem; line-height: 1rem; "></div>
    <!-- 按鈕 -->
    <div style="background: #418BCA; width: 80%; margin: 0 auto; height: 1.5rem; line-height: 1.5rem; text-align: center;color: #fff;margin-top: 1rem; -moz-border-radius: .128rem; -webkit-border-radius: .128rem; border-radius: .128rem;font-size: .59733rem;" onclick="closeWindow()">
        確 定
    </div>
</div>

 

js代碼:(把jq引進來)

<script type="text/javascript">
   // 彈窗 function showWindow(showmsg) { $('#showdiv').show(); //顯示彈窗 $('.content').append(showmsg); //追加內容 $('#cover').css('display','block'); //顯示遮罩層 } // 關閉彈窗 function closeWindow() { $('#showdiv').hide(); //隱藏彈窗 $('#cover').css('display','none'); //顯示遮罩層 $('#showdiv .content').html(""); //清空追加的內容 }

//調用
showWindow('
js彈窗 js彈出DIV,並使整個頁面背景變暗');

</script>

 

 

效果:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM