在 iframe 子頁面寫模態框時,按照以前的寫法,點擊彈出模態框的按鈕之后一直沒有反應,但代碼并沒有寫錯,代碼如下:
<input class="btn" id="deletebutton" type="button" value="刪貼" onclick="deletePost()"/><!-- 管理員發送消息模態框 2017.1.25 --><div id="messageModal" class="modal fade" role="dialog" style="display:none"> <div class="modal-header" > <a class="close" data-dismiss="modal">×</a> <h3>發送消息給本貼貼主</h3> </div> <div class="modal-body" > <h4 style="text-align:center;color:red" id="errorMessage"></h4><br/> <h4 style="text-align:center">請輸入消息內容:<input id="messageContent" type="text" style="width:40%;height:15%" ></h4><br/> </div> <div class="modal-footer" > <a href="#" rel="external nofollow" rel="external nofollow" class="btn btn-success" onclick="callPostEditor()">發送</a> <a href="#" rel="external nofollow" rel="external nofollow" class="btn bt" onclick="reSet()">重置</a> </div></div>
在網上搜索了很久也沒找到原因,但是看到一種方法,是把模態框的html代碼放置到父頁面上,然后使用:
window.parent.$('#messageModal').modal('show');來調用模態框顯示。
如果子頁面有js方法在模態框中調用,再通過下面的語句實現調用:
// Conframe是父頁面的iframe標簽的name屬性(注意:不能用id屬性,在Firefox中不能獲取iframe的id屬性)Conframe.window.callPostEditor();
即“iframe的name屬性.windows.方法名()”。
以上這篇在iFrame子頁面里實現模態框的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持錯新站長站。
新聞熱點
疑難解答
圖片精選