1$(document).on('show.bs.modal', '.modal', function (event) {
2 var zIndex = 1040 + (10 * $('.modal:visible').length);
3 $(this).css('z-index', zIndex);
4 setTimeout(function() {
5 $('.modal-backdrop').not('.modal-stack').css('z-index', zIndex - 1).addClass('modal-stack');
6 }, 0);
7});