Jquery to open Bootstrap v3 modal of remote url

后端 未结 6 1237
孤街浪徒
孤街浪徒 2020-12-01 08:02

I have a page of links to internal pages I need to open up in a Bootstrap modal DIV. The problem is that it seems that using the latest version of Bootstrap v3 in conjunctio

6条回答
  •  情话喂你
    2020-12-01 08:16

    From Bootstrap's docs about the remote option;

    This option is deprecated since v3.3.0 and has been removed in v4. We recommend instead using client-side templating or a data binding framework, or calling jQuery.load yourself.

    If a remote URL is provided, content will be loaded one time via jQuery's load method and injected into the .modal-content div. If you're using the data-api, you may alternatively use the href attribute to specify the remote source. An example of this is shown below:

    Click me
    

    That's the .modal-content div, not .modal-body. If you want to put content inside .modal-body then you need to do that with custom javascript.

    So I would call jQuery.load programmatically, meaning you can keep the functionality of the dismiss and/or other buttons as required.

    To do this you could use a data tag with the URL from the button that opens the modal, and use the show.bs.modal event to load content into the .modal-body div.

    HTML Link/Button

    Click me
    

    jQuery

    $('#myModal').on('show.bs.modal', function (e) {
        var loadurl = $(e.relatedTarget).data('load-url');
        $(this).find('.modal-body').load(loadurl);
    });
    

提交回复
热议问题