bootstrap-4 - 如何使用 bootstrap 4.4.x 模式从外部页面加载内容
问题描述
我想将外部页面的内容加载到Bootstrap 4.4模式中。这是我的演示
JS:
$('#theModal').on('show.bs.modal', function (e) {
var button = $(e.relatedTarget);
var modal = $(this);
// load content from HTML string
//modal.find('.modal-body').html("Nice modal body baby...");
// or, load content from value of data-remote url
modal.find('.modal-body').load(button.data("remote"));
});
HTML:
<ul class="nav flex-row" id="menu">
<li>
<a href="/" class="nav-link">Link</a>
</li>
<li>
<a href="/" class="nav-link">Link</a>
</li>
<li>
<a href="#theModal" class="nav-link" data-remote="https://www.lipsum.com" data-toggle="modal" data-target="#theModal">Modal</a>
</li>
</ul>
<div class="modal fade" id="theModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">My modal</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
... remote content from "data-remote" loads here ...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Send message</button>
</div>
</div>
</div>
</div>
我该如何做到这一点?
解决方案
最终,我解决了这个问题。在我的身体标签中,我有引导程序的脚本,例如
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>
我所做的是,我删除了
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
crossorigin="anonymous"></script>
此脚本条目来自 body 标记,并将 jQuery cdn 链接添加到 header 标记。
这对我来说很有用。
推荐阅读
- c# - 发生 SQLException:“”附近的语法不正确
- python - Python多处理抓取,重复结果
- android - 数据库写入率
- ios - 推送转换后 iOS Button 未完全呈现
- r - 尝试使用 R 抓取整个表格,但只能获得第一行
- javascript - 如何在 clickOutsideToClose 和 $mdDialog.hide() 之后接收 promise.finally 的参数
- c# - 使用 dotnet core 解压缩 .taz 文件
- javascript - 使用 JQuery 遍历多个输入字段
- python-3.x - 更改由 hashlib 创建的哈希对象的算法常量
- java - 如何将数字转换为字母(A = 0、B = 1、C = 2 等...)