Twitter bootstrap remote modal shows same content every time

前端 未结 22 995
春和景丽
春和景丽 2020-11-22 12:29

I am using Twitter bootstrap, I have specified a modal

<
相关标签:
22条回答
  • 2020-11-22 13:02

    The accepted answer didn't work for me, so I went with JavaScript to do it.

    <a href="/foo" class="modal-link">
    <a href="/bar" class="modal-link">
    
    <script>
    $(function() {
        $(".modal-link").click(function(event) {
            event.preventDefault()
            $('#myModal').removeData("modal")
            $('#myModal').modal({remote: $(this).attr("href")})
        })
    })
    
    0 讨论(0)
  • 2020-11-22 13:03

    Why not make it more general with BS 3? Just use "[something]modal" as the ID of the modal DIV.

    $("div[id$='modal']").on('hidden.bs.modal',
        function () {
            $(this).removeData('bs.modal');
        }
    );
    
    0 讨论(0)
  • 2020-11-22 13:04

    This other approach works well for me:

    $("#myModal").on("show.bs.modal", function(e) {
        var link = $(e.relatedTarget);
        $(this).find(".modal-body").load(link.attr("href"));
    });
    
    0 讨论(0)
  • 2020-11-22 13:05

    Thanks merv. I started tinkering around boostrap.js but your answer is a quick and clean workaround. Here's what I ended up using in my code.

    $('#modal-item').on('hidden', function() {
        $(this).removeData('modal');
    });
    
    0 讨论(0)
  • 2020-11-22 13:05

    In Bootstrap 3.2.0 the "on" event has to be on the document and you have to empty the modal :

    $(document).on("hidden.bs.modal", function (e) {
        $(e.target).removeData("bs.modal").find(".modal-content").empty();
    });
    

    In Bootstrap 3.1.0 the "on" event can be on the body :

    $('body').on('hidden.bs.modal', '.modal', function () {
        $(this).removeData('bs.modal');
    });
    
    0 讨论(0)
  • 2020-11-22 13:05

    Only working option for me is:

    $('body').on('hidden.bs.modal', '#modalBox', function () {
        $(this).remove();
    });
    

    I use Bootstrap 3 and I have a function called popup('popup content') which appends the modal box html.

    0 讨论(0)
提交回复
热议问题