I am using Twitter bootstrap, I have specified a modal
<
-
The accepted answer didn't work for me, so I went with JavaScript to do it.
<a href="/foo" class="modal-link">
<a href="/bar" class="modal-link">
<script>
$(function() {
$(".modal-link").click(function(event) {
event.preventDefault()
$('#myModal').removeData("modal")
$('#myModal').modal({remote: $(this).attr("href")})
})
})
讨论(0)
-
Why not make it more general with BS 3? Just use "[something]modal" as the ID of the modal DIV.
$("div[id$='modal']").on('hidden.bs.modal',
function () {
$(this).removeData('bs.modal');
}
);
讨论(0)
-
This other approach works well for me:
$("#myModal").on("show.bs.modal", function(e) {
var link = $(e.relatedTarget);
$(this).find(".modal-body").load(link.attr("href"));
});
讨论(0)
-
Thanks merv. I started tinkering around boostrap.js but your answer is a quick and clean workaround. Here's what I ended up using in my code.
$('#modal-item').on('hidden', function() {
$(this).removeData('modal');
});
讨论(0)
-
In Bootstrap 3.2.0 the "on" event has to be on the document and you have to empty the modal :
$(document).on("hidden.bs.modal", function (e) {
$(e.target).removeData("bs.modal").find(".modal-content").empty();
});
In Bootstrap 3.1.0 the "on" event can be on the body :
$('body').on('hidden.bs.modal', '.modal', function () {
$(this).removeData('bs.modal');
});
讨论(0)
-
Only working option for me is:
$('body').on('hidden.bs.modal', '#modalBox', function () {
$(this).remove();
});
I use Bootstrap 3 and I have a function called
popup('popup content')
which appends the modal box html.
讨论(0)