国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

在iframe中使bootstrap的模態(tài)框在父頁面彈出問題

2019-11-19 15:53:04
字體:
供稿:網(wǎng)友

這幾天在寫項目的中,頁面使用了iframe,然而在子頁面中使用bootstrap的模態(tài)框時發(fā)現(xiàn):彈出的模態(tài)框位置是以子頁面為標準居中的,并且遮罩層也只有子頁面那一部分,整個頁面簡直無法直視,所以思考可以可以讓模態(tài)框以父頁面為標準彈出,經(jīng)過在網(wǎng)上查找資料,總結(jié)了一種解決方法。

效果展示

修改前頁面

這里寫圖片描述

修改后頁面

這里寫圖片描述

實現(xiàn)思路

要想使模態(tài)框在頂級頁面打開,我想到的方法是使bootstrap的模態(tài)框彈在父頁面彈出即可。

首先我們將需要彈出的div單獨寫一個頁面,當子頁面需要彈出時,在父頁面彈出div即可。

將模態(tài)框單獨寫為一個頁面

主頁面

<!DOCTYPE html><html>  <head>    <meta charset="utf-8" />    <title></title>  </head>  <body>    <div class="modal fade" id="ajax" role="basic" aria-hidden="true">      <div class="modal-dialog">        <div class="modal-content">        </div>      </div>    </div>  </body>  <script>      $("#ajax").modal({        remote: "./model.html"      });  </script></html>

模態(tài)框頁面

<div class="modal-content">  <div class="modal-header">    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>    <h4 class="modal-title" id="myModalLabel">Modal title</h4>  </div>  <div class="modal-body">    這是模態(tài)框  </div>  <div class="modal-footer">    <button type="button" class="btn btn-primary">保存</button>    <button type="button" class="btn btn-default" data-dismiss="modal">關(guān)閉</button>  </div></div>

這樣就可以將模態(tài)框的div單獨寫為一個頁面

修改主頁面,加入子頁面

修改后主頁面

<!DOCTYPE html><html>  <head>    <meta charset="utf-8" />    <title></title>  </head>  <body>    <table width="100%" height="720px" border="1">      <tr>        <td>          <iframe id="iframe1" name="iframe1" src="iframe1.html" width="100%" height="100%"></iframe>        </td>        <td></td>      </tr>      <tr>        <td></td>        <td>          <iframe name="iframe2" src="iframe2.html" width="100%" height="100%"></iframe>        </td>      </tr>    </table>    <input type="text" id="textId" value="234" />    <div class="modal fade" id="ajax" role="basic" aria-hidden="true">      <div class="modal-dialog">        <div class="modal-content">        </div>      </div>    </div>  </body>  <script>    function modalOut(url) {      $("#ajax").modal({        remote: url;      });    }  </script></html>

這樣主頁面就有2個子頁面,并且將彈出模態(tài)框的方法封裝至modalOut(url)方法中

子頁面彈出模態(tài)框

當子頁面需要彈出模態(tài)框時,加載父頁面中的modalOut(url)方法即可:

子頁面js如下

var _iframe = window.parent;_iframe.modalOut('xxx.html');

以上就是解決子頁面中彈出模態(tài)框無法覆蓋全部頁面的解決辦法,

注意:所以html中未加載js,請自行加載bootstrap相關(guān)的js。

總結(jié)

以上所述是小編給大家介紹的在iframe中使bootstrap的模態(tài)框在父頁面彈出問題,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對武林網(wǎng)網(wǎng)站的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 呈贡县| 任丘市| 开平市| 镇康县| 轮台县| 新乡市| 咸丰县| 榆树市| 日土县| 阿拉善右旗| 江都市| 孙吴县| 新绛县| 十堰市| 宁波市| 东丽区| 滁州市| 化德县| 延安市| 叶城县| 黎川县| 突泉县| 青神县| 辽中县| 泾源县| 卢氏县| 正蓝旗| 泸州市| 巴楚县| 革吉县| 雷波县| 四会市| 朝阳市| 朝阳区| 双鸭山市| 兴海县| 应用必备| 洪江市| 德钦县| 那曲县| 集贤县|