如何使用引导程序4.4.x模态从外部页面加载内容

问题描述 投票:0回答:1

我想将外部页面的内容加载到Bootstrap 4.4模式中。这是我的demo

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>

我该如何实现?

bootstrap-4 bootstrap-modal
1个回答
0
投票

最终,我解决了这个问题。在我的身体标签中,我有[>]这样的引导程序脚本

<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/[email protected]/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链接。

对我来说很好。

© www.soinside.com 2019 - 2024. All rights reserved.