I am using Twitter bootstrap, I have specified a modal
<
-
Adding an $(this).html(''); to clear visible data as well, and it works pretty fine
讨论(0)
-
This works with Bootstrap 3 FYI
$('#myModal').on('hidden.bs.modal', function () {
$(this).removeData('bs.modal');
});
讨论(0)
-
For Bootstrap 3, in modal.js I changed:
$(document)
.on('show.bs.modal', '.modal', function () { $(document.body).addClass('modal-open') })
.on('hidden.bs.modal', '.modal', function () { $(document.body).removeClass('modal-open'); })
to
$(document)
.on('show.bs.modal', '.modal', function () { $(document.body).addClass('modal-open') })
.on('hidden.bs.modal', '.modal', function () {
$(this).removeData('bs.modal').empty()
$(document.body).removeClass('modal-open')
})
(extra spacing added for clarity)
This prevents any unwanted flash of old modal content by calling empty() on the modal container as well as removing the data.
讨论(0)
-
$('body').on('hidden.bs.modal', '.modal', function () {
$("#mention Id here what you showed inside modal body").empty()
});
Which html element you want to empty like(div,span whatever).
讨论(0)
-
This one works for me:
modal
<div class="modal fade" id="searchKaryawan" tabindex="-1" role="dialog" aria-labelledby="SearchKaryawanLabel" aria-hidden="true"> <div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="SearchKaryawanLabel">Cari Karyawan</h4>
</div>
<div class="modal-body">
<input type="hidden" name="location">
<input name="cariNama" type="text" class="form-control" onkeyup="if (this.value.length > 3) cariNikNama();" />
<div class="links-area" id="links-area"></div>
</div>
<div class="modal-footer">
</div>
</div> </div></div>
script
<script type="text/javascript">$('body').on('hidden.bs.modal', '.modal', function () { $(".links-area").empty() }); </script>
links-area is area where i put the data and need to clear
讨论(0)
-
Tested on Bootstrap version 3.3.2
$('#myModal').on('hide.bs.modal', function() {
$(this).removeData();
});
讨论(0)