Twitter bootstrap remote modal shows same content every time

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

I am using Twitter bootstrap, I have specified a modal

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

    For bootstrap 3 you should use:

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

    I've added something like this, because the older content is shown until the new one appears, with .html('') inside the .modal-content will clear the HTML inside, hope it helps

    $('#myModal').on('hidden.bs.modal', function () {
       $('#myModal').removeData('bs.modal');
       $('#myModal').find('.modal-content').html('');
    });
    
    0 讨论(0)
  • 2020-11-22 13:28

    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

    $.ajaxSetup ({
        // Disable caching of AJAX responses
        cache: false
    });
    
    0 讨论(0)
  • 2020-11-22 13:29

    I wrote a simple snippet handling the refreshing of the modal. Basically it stores the clicked link in the modal's data and check if it's the same link that has been clicked, removing or not the modal data.

    var handleModal = function()
    {
        $('.triggeringLink').click(function(event) {
            var $logsModal = $('#logsModal');
            var $triggeringLink = $logsModal.data('triggeringLink');
    
            event.preventDefault();
    
            if ($logsModal.data('modal') != undefined
                && $triggeringLink != undefined
                && !$triggeringLink.is($(this))
            ) {
                $logsModal.removeData('modal');
            }
    
            $logsModal.data('triggeringLink', $(this));
    
            $logsModal.modal({ remote: $(this).attr('href') });
            $logsModal.modal('show');
        });
    };
    
    0 讨论(0)
提交回复
热议问题