Here is my modal html code:
-
To extend @JoshCrozier's answer:
It would be nice if they had a property like that associated with the hide.bs.modal/hidden.bs.modal events. As of writing this, there currently isn't
This will emulate a similar behaviour, that attaches the clicked button as relatedTarget for later listeners:
$( '.modal-footer .btn[data-dismiss="modal"]' ).on( 'click', function() {
var target = this
$( target ).closest( '.modal' )
.one( 'hide.bs.modal hidden.bs.modal', function( event ) {
event.relatedTarget = target
} )
} )
The selector and listener can be further optimized depending on how the modals are used in a project. For example: if you know you're not going to use hide.bs.modal you can just modify hidden.bs.modal's event instead.
- 热议问题