Reload content in modal (twitter bootstrap)

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

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


      
      
14条回答
  •  暖寄归人
    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,

    
    

    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.

提交回复
热议问题