Reload content in modal (twitter bootstrap)

前端 未结 14 1683
青春惊慌失措
青春惊慌失措 2020-12-02 04:38

I\'m using twitter bootstrap\'s modal popup.


      
      
14条回答
  • 2020-12-02 05:30

    Based on other answers (thanks everyone).

    I needed to adjust the code to work, as simply calling .html wiped the whole content out and the modal would not load with any content after i did it. So i simply looked for the content area of the modal and applied the resetting of the HTML there.

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

    Still may go with the accepted answer as i am getting some ugly jump just before the modal loads as the control is with Bootstrap.

    0 讨论(0)
  • 2020-12-02 05:30

    I made a small change to Softlion answer, so all my modals won't refresh on hide. The modals with data-refresh='true' attribute are only refreshed, others work as usual. Here is the modified version.

    $(document).on('hidden.bs.modal', function (e) {
        if ($(e.target).attr('data-refresh') == 'true') {
            // Remove modal data
            $(e.target).removeData('bs.modal');
            // Empty the HTML of modal
            $(e.target).html('');
        }
    });
    

    Now use the attribute as shown below,

    <div class="modal fade" data-refresh="true" id="#modal" tabindex="-1" role="dialog" aria-labelledby="#modal-label" aria-hidden="true"></div>
    

    This will make sure only the modals with data-refresh='true' are refreshed. And i'm also resetting the modal html because the old values are shown until new ones get loaded, making html empty fixes that one.

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