這篇文章主要介紹bootstrap如何實現嵌套模態(tài)框,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

項目上有一個需求,需要在已經彈出的一個bootstrap模態(tài)框的基礎上再彈一個模態(tài)框。
因為bootstrap官方不建議這么做,最后實現的過程屬實不易。
以下是解決方案:
html代碼:
<div id="container"> <a data-toggle="modal" href="#myModal" rel="external nofollow" class="btn btn-primary">彈出第一層模態(tài)框</a> <!-- 第一層模態(tài)框 --> <div class="modal fade" id="myModal"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h5 class="modal-title">第一層模態(tài)框</h5> </div> <div class="container"></div> <div class="modal-body"> <p>第一層模態(tài)框</p> <br> <a data-toggle="modal" href="#myModal2" rel="external nofollow" class="btn btn-primary">彈出第二層模態(tài)框</a> </div> <div class="modal-footer"> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" data-dismiss="modal" class="btn">關閉</a> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="btn btn-primary">保存</a> </div> </div> </div> </div> <!-- 第二層模態(tài)框 --> <div class="modal fade rotate" id="myModal2"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h5 class="modal-title">第二層模態(tài)框</h5> </div> <div class="container"></div> <div class="modal-body"> <p>第二層模態(tài)框</p> </div> <div class="modal-footer"> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" data-dismiss="modal" class="btn">關閉</a> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="btn btn-primary">保存</a> </div> </div> </div> </div> <!-- 遮罩 --> <div id="cover"></div> </div>
遮罩的css樣式:
<style type="text/css">
<!-- 遮罩是為了第二層模態(tài)框彈出時,可以將第一層模態(tài)框遮住 -->
#cover {
display: none;
position: fixed;
background: #000000;
left: 0;
top: 0;
width: 100%;
height: 100%;
opacity: 0.40;
z-index: 1
}
</style>js代碼:
$(document).ready(function (){
//第二層模態(tài)框彈出時,為其設置一個大于第一層模態(tài)框的z-index
//使得第二層模態(tài)框可以在第一層模態(tài)框上面
$(document).on('show.bs.modal', '#myModal2', function (event) {
var zIndex = 1040 + (10 * $('.modal:visible').length+1);
$(this).css('z-index', zIndex);
//開啟遮罩,遮罩的高度小于第二層模態(tài)框
$("#cover").css('z-index',zIndex-1)
$('#cover').css('display','block'); //顯示遮罩層
});
$('#myModal2').on('hide.bs.modal', function() {
//第二層模態(tài)框關閉時,關閉遮罩
$('#cover').css('display','none');
});
});以上是“bootstrap如何實現嵌套模態(tài)框”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注創(chuàng)新互聯成都網站設計公司行業(yè)資訊頻道!
另外有需要云服務器可以了解下創(chuàng)新互聯scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
網頁名稱:bootstrap如何實現嵌套模態(tài)框-創(chuàng)新互聯
文章鏈接:http://chinadenli.net/article24/edjje.html
成都網站建設公司_創(chuàng)新互聯,為您提供虛擬主機、營銷型網站建設、網站內鏈、網站排名、品牌網站設計、網站制作
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯