I have a problem with a close modal in bootstrap. When I open modal windows with data (modal content change based on start button). This is an example at http://getbootstrap.com/javascript/#modals
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Open modal for @mdo</button> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@fat">Open modal for @fat</button> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@getbootstrap">Open modal for @getbootstrap</button> ...more buttons... <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"> <div class="modal-dialog" role="document"> <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="exampleModalLabel">New message</h4> </div> <div class="modal-body"> <form> <div class="form-group"> <label for="recipient-name" class="control-label">Recipient:</label> <input type="text" class="form-control" id="recipient-name"> </div> <div class="form-group"> <label for="message-text" class="control-label">Message:</label> <textarea class="form-control" id="message-text"></textarea> </div> </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" id="btnclose" data-dismiss="modal">Close</button> <button type="button" id="btnsend" class="btn btn-primary">Send message</button> </div> </div> </div> </div>
This is normal, but if I close the modal and open it in another button, when I click the send to print button, the value of the recipient of the first modal and this modal is registered in the console. But I only need to print the last value of the recipient. I don't understand why the stack events of the previous modal close. This is my jquery code for both buttons:
$('#exampleModal').on('show.bs.modal', function (event) { var button = $(event.relatedTarget)
Thank you very much, and I hope someone can help me. https://jsfiddle.net/DTcHh/28480/
source share