Reload content in modal (twitter bootstrap)

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

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


      
      
14条回答
  •  一个人的身影
    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:

    click me
    click me2
    click me3
    

提交回复
热议问题