比方說,你有2頁,index.htm
和somepage.htm
你有index.htm
頁模式,並要顯示somepage.htm
內模態。然後
index.htm網頁代碼會
<a href="somepage.htm" data-toggle="modal" data-target="#extLinkModal">
<div class="modal fade" id="extLinkModal" tabindex="-1" role="dialog" aria-labelledby="extlinkModalLabel" aria-hidden="true" data-backdrop="static">
<div class="modal-dialog " role="document">
<div class="modal-content">
//Here you can show the content from `somepage.htm`
</div>
</div>
</div>
和somepage.htm頁面內容將是
<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="extLinkModalLabel"></h4>
</div>
<div class="modal-body">
//Put the page content here
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
這將解決該問題somepage.htm溢出了模態的,有模式上沒有滾動條
備用解決方案
OP在評論中問道,遠程頁面內容加載到modal-body
和上面的代碼示例是引導V3的默認行爲+地方模式忽略modal-body
始終加載遠程內容到<div class="modal-content">
不要緊,即使<div class="modal-body">
的<div class="modal-content">
內部存在。
爲了解決這個問題,並確保內部<div class="modal-body">
- 使用遠程內容加載自舉模式events
- 不要在模態呼叫按鈕或鏈接
因此,使用href
或remote
模態呼叫按鈕或鏈接將爲
<a datalink="somepage.htm" data-toggle="modal" data-target="#extLinkModal" class="btn btn-primary">
其中href
改爲datalink
或任何字可以被使用,但不href
或remote
否則模態將其檢測爲遠程內容而忽略<div class="modal-body">
和內容加載到<div class="modal-content">
模態HTML
<div class="modal fade" id="extLinkModal" tabindex="-1" role="dialog" aria-labelledby="extlinkModalLabel" aria-hidden="true" data-backdrop="static">
<div class="modal-dialog " role="document">
<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="extLinkModalLabel"></h4>
</div>
<div class="modal-body">
//Remote Page Content loads here
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
和JS
<script>
$(document).ready(function() {
$("#extLinkModal").on("show.bs.modal", function(e) {
var link = $(e.relatedTarget);
$(this).find(".modal-body").load(link.attr("datalink"));
});
});
</script>
但我希望顯示somepage.htm的整個頁面。換句話說,我試圖加載一個外部頁面,類似於如何在iframe中加載頁面。我怎麼能做到這一點,而不必在我希望加載的每個頁面中添加模態主體? – adam78
答覆已更新。 – Shehary