1$(document).on('show.bs.modal', '.modal', function(event) { 2 $(this).appendTo($('body')); 3 }).on('shown.bs.modal', '.modal.in', function(event) { 4 setModalsAndBackdropsOrder(); 5 }).on('hidden.bs.modal', '.modal', function(event) { 6 setModalsAndBackdropsOrder(); 7 }); 8 9 10 function setModalsAndBackdropsOrder() { 11 var modalZIndex = 1040; 12 $('.modal.in').each(function(index) { 13 var $modal = $(this); 14 modalZIndex++; 15 $modal.css('zIndex', modalZIndex); 16 $modal.next('.modal-backdrop.in').addClass('hidden').css('zIndex', modalZIndex - 1); 17 }); 18 $('.modal.in:visible:last').focus().next('.modal-backdrop.in').removeClass('hidden'); 19 }
该操作的可能后果:
对应的model将会被移动到body外创建,一旦页面使用单页面技术框架类似于AngularJs相关的话,将会造成路由再次跳回的时候,model重复加载。不太建议直接这样实现。
若多Model弹窗的话 还有一种就是修改对应的层级model对应的z-index。