Reload content in modal (twitter bootstrap)

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

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


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

    I wanted the AJAX loaded content removed when the modal closed, so I adjusted the line suggested by others (coffeescript syntax):

    $('#my-modal').on 'hidden.bs.modal', (event) ->
      $(this).removeData('bs.modal').children().remove()
    
    0 讨论(0)
  • 2020-12-02 05:08

    var $table = $('#myTable2');
    $table.bootstrapTable('destroy');

    Worked for me

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

    I was also stuck on this problem then I saw that the ids of the modal are the same. You need different ids of modals if you want multiple modals. I used dynamic id. Here is my code in haml:

    .modal.hide.fade{"id"=> discount.id,"aria-hidden" => "true", "aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}
    

    you can do this

    <div id="<%= some.id %>" class="modal hide fade in">
      <div class="modal-header">
        <a class="close" data-dismiss="modal">×</a>
        <h3>Header</h3>
      </div>
      <div class="modal-body"></div>
      <div class="modal-footer">
        <input type="submit" class="btn btn-success" value="Save" />
      </div>
    </div>
    

    and your links to modal will be

    <a data-toggle="modal" data-target="#" href='"#"+<%= some.id %>' >Open modal</a>
    <a data-toggle="modal" data-target="#myModal" href='"#"+<%= some.id %>' >Open modal</a>
    <a data-toggle="modal" data-target="#myModal" href='"#"+<%= some.id %>' >Open modal</a>
    

    I hope this will work for you.

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

    Here is a coffeescript version that worked for me.

    $(document).on 'hidden.bs.modal', (e) ->
      target = $(e.target)
      target.removeData('bs.modal').find(".modal-content").html('')
    
    0 讨论(0)
  • 2020-12-02 05:11

    With Bootstrap 3 you can use 'hidden.bs.modal' event handler to delete any modal-related data, forcing the popup to reload next time:

    $('#modal').on('hidden.bs.modal', function() {
        $(this).removeData('bs.modal');
    });
    
    0 讨论(0)
  • 2020-12-02 05:14

    A little more compressed than the above accepted example. Grabs the target from the data-target of the current clicked anything with data-toggle=modal on. This makes it so you don't have to know what the id of the target modal is, just reuse the same one! less code = win! You could also modify this to load title, labels and buttons for your modal should you want to.

     $("[data-toggle=modal]").click(function(ev) {
        ev.preventDefault();
        // load the url and show modal on success
        $( $(this).attr('data-target') + " .modal-body").load($(this).attr("href"), function() { 
             $($(this).attr('data-target')).modal("show"); 
        });
    });
    

    Example Links:

    <a data-toggle="modal" href="/page/api?package=herp" data-target="#modal">click me</a>
    <a data-toggle="modal" href="/page/api?package=derp" data-target="#modal">click me2</a>
    <a data-toggle="modal" href="/page/api?package=merp" data-target="#modal">click me3</a>
    
    0 讨论(0)
提交回复
热议问题