bootstrap實(shí)現(xiàn)嵌套模態(tài)框的實(shí)例代碼
項(xiàng)目上有一個(gè)需求,需要在已經(jīng)彈出的一個(gè)bootstrap模態(tài)框的基礎(chǔ)上再?gòu)椧粋€(gè)模態(tài)框。
因?yàn)閎ootstrap官方不建議這么做,最后實(shí)現(xiàn)的過(guò)程屬實(shí)不易。
以下是解決方案:
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">關(guān)閉</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">關(guān)閉</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)框彈出時(shí),可以將第一層模態(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)框彈出時(shí),為其設(shè)置一個(gè)大于第一層模態(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); //開(kāi)啟遮罩,遮罩的高度小于第二層模態(tài)框 $("#cover").css('z-index',zIndex-1) $('#cover').css('display','block'); //顯示遮罩層 }); $('#myModal2').on('hide.bs.modal', function() { //第二層模態(tài)框關(guān)閉時(shí),關(guān)閉遮罩 $('#cover').css('display','none'); }); });
總結(jié)
以上所述是小編給大家介紹的bootstrap實(shí)現(xiàn)嵌套模態(tài)框的實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)我們網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
上一篇:沒(méi)有了
欄 目:JavaScript
下一篇:沒(méi)有了
本文標(biāo)題:bootstrap實(shí)現(xiàn)嵌套模態(tài)框的實(shí)例代碼
本文地址:http://mengdiqiu.com.cn/a1/JavaScript/9232.html
您可能感興趣的文章
- 04-02java后端代碼分頁(yè) java后端實(shí)現(xiàn)分頁(yè)page
- 01-10Echarts實(shí)現(xiàn)單條折線可拖拽效果
- 01-10在Vue項(xiàng)目中使用Typescript的實(shí)現(xiàn)
- 01-10js實(shí)現(xiàn)上傳圖片并顯示圖片名稱
- 01-10Vue中使用Lodop插件實(shí)現(xiàn)打印功能的簡(jiǎn)單方法
- 01-10echarts實(shí)現(xiàn)折線圖的拖拽效果
- 01-10d3.js實(shí)現(xiàn)圖形縮放平移
- 01-10小程序簡(jiǎn)單兩欄瀑布流效果的實(shí)現(xiàn)
- 01-10H5實(shí)現(xiàn)手機(jī)拍照和選擇上傳功能
- 01-10Echarts實(shí)現(xiàn)多條折線可拖拽效果


閱讀排行
- 1C語(yǔ)言 while語(yǔ)句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹(shù)的示例代碼(圣誕
- 3利用C語(yǔ)言實(shí)現(xiàn)“百馬百擔(dān)”問(wèn)題方法
- 4C語(yǔ)言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語(yǔ)言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語(yǔ)言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語(yǔ)言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 04-02javascript點(diǎn)線,點(diǎn)線的代碼
- 04-02javascript潛力,javascript強(qiáng)大嗎
- 04-02javascript替換字符串,js字符串的替換
- 04-02javascript移出,js 移入移出
- 04-02包含javascript舍的詞條
- 04-02javascript并行,深入理解并行編程 豆瓣
- 04-02javascript匿名,js匿名方法
- 04-02javascript警報(bào),JavaScript警告
- 04-02javascript遮蓋,JavaScript遮蓋PC端頁(yè)面
- 04-02javascript前身,javascript的前身
隨機(jī)閱讀
- 01-10SublimeText編譯C開(kāi)發(fā)環(huán)境設(shè)置
- 01-11ajax實(shí)現(xiàn)頁(yè)面的局部加載
- 01-11Mac OSX 打開(kāi)原生自帶讀寫(xiě)NTFS功能(圖文
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 01-10delphi制作wav文件的方法
- 04-02jquery與jsp,用jquery
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 01-10C#中split用法實(shí)例總結(jié)
- 01-10使用C語(yǔ)言求解撲克牌的順子及n個(gè)骰子
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什