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>
<h4 class="modal-title">第一層模態(tài)框</h4>
</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>
<h4 class="modal-title">第二層模態(tài)框</h4>
</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)框的實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對我們網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
上一篇:沒有了
欄 目:JavaScript
下一篇:沒有了
本文標題:bootstrap實現嵌套模態(tài)框的實例代碼
本文地址:http://www.jygsgssxh.com/a1/JavaScript/9232.html
您可能感興趣的文章
- 04-02java后端代碼分頁 java后端實現分頁page
- 01-10Echarts實現單條折線可拖拽效果
- 01-10在Vue項目中使用Typescript的實現
- 01-10js實現上傳圖片并顯示圖片名稱
- 01-10Vue中使用Lodop插件實現打印功能的簡單方法
- 01-10echarts實現折線圖的拖拽效果
- 01-10d3.js實現圖形縮放平移
- 01-10小程序簡單兩欄瀑布流效果的實現
- 01-10H5實現手機拍照和選擇上傳功能
- 01-10Echarts實現多條折線可拖拽效果


閱讀排行
本欄相關
- 04-02javascript點線,點線的代碼
- 04-02javascript潛力,javascript強大嗎
- 04-02javascript替換字符串,js字符串的替換
- 04-02javascript移出,js 移入移出
- 04-02包含javascript舍的詞條
- 04-02javascript并行,深入理解并行編程 豆瓣
- 04-02javascript匿名,js匿名方法
- 04-02javascript警報,JavaScript警告
- 04-02javascript遮蓋,JavaScript遮蓋PC端頁面
- 04-02javascript前身,javascript的前身
隨機閱讀
- 01-10SublimeText編譯C開發(fā)環(huán)境設置
- 01-11ajax實現頁面的局部加載
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 08-05dedecms(織夢)副欄目數量限制代碼修改
- 01-10delphi制作wav文件的方法
- 04-02jquery與jsp,用jquery
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 01-10C#中split用法實例總結
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 08-05DEDE織夢data目錄下的sessions文件夾有什


