bootstrap同一页面上多个模态框
非原创,很久以前一篇大佬的日记了,忘了出处
$(document).on('show.bs.modal', '.modal', function(event) { $(this).appendTo($('body')); }).on('shown.bs.modal', '.modal.in', function(event) { setModalsAndBackdropsOrder(); }).on('hidden.bs.modal', '.modal', function(event) { setModalsAndBackdropsOrder(); }); function setModalsAndBackdropsOrder() { var modalZIndex = 1040; $('.modal.in').each(function(index) { var $modal = $(this); modalZIndex++; $modal.css('zIndex', modalZIndex); $modal.next('.modal-backdrop.in').addClass('hidden').css('zIndex', modalZIndex - 1); }); $('.modal.in:visible:last').focus().next('.modal-backdrop.in').removeClass('hidden'); }