Unable to removedata from modal on close.Showing s

2020-05-01 16:41发布

问题:

Unable to removedata from modal on close.Showing same content everytime

$('body').on('hidden.bs.modal', '.modal', function () {
  $(this).removeData('bs.modal');
});

This function is also not working.

回答1:

Had a same problem, when i am passing data to same modal, and remove content. The best solution, and only got is to use bootBox

http://bootboxjs.com/

bootbox.dialog({
  message: "I am a custom dialog",
  title: "Custom title",
  buttons: {
    success: {
      label: "Success!",
      className: "btn-success",
      callback: function() {
        Example.show("great success");
      }
    },
    danger: {
      label: "Danger!",
      className: "btn-danger",
      callback: function() {
        Example.show("uh oh, look out!");
      }
    },
    main: {
      label: "Click ME!",
      className: "btn-primary",
      callback: function() {
        Example.show("Primary button");
      }
    }
  }
});


回答2:

try in this way for Bootstrap v3.2.0

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

example of generic modal

<div class="modal hide" id="">

    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">x</button>

    </div>    

    <div class="modal-body">

    </div>

    <div class="modal-footer">

    </div>

</div>


回答3:

men i can finally made ir works

shoud be.

        $('body').on('hide.bs.modal', '.modal', function (e) {
        $(this).find('form').trigger("reset");
    });

in this post I cant clear form data from bootstrap modal Sadikhasan user nailed it, you need to clear form data but $(this) is the modal div, so you need to find the form inside the modal and reset it.