一、问题

在项目里忽然新加了一个需求,在原本弹出的模态框里,点击模态框里面的按钮再弹出一个模态框,出来另个模态框来展示详细信息。此时就存在两个模态框在这个需求没加之前有一个弹出的模态框也是需要继续点击(大致示意图如下),那个是时候去查过bootstrap的这个modal,官网上写着:

不支持同时打开多个模态框
千万不要在一个模态框上重叠另一个模态框。要想同时支持多个模态框,需要自己写额外的代码来实现。

于是就没打算同时打开多个模态框,因为第二个模态框打开后不再需要第一个模态框,于是就将这个功能改成当点击按钮后,将原本的模态框关闭,然后再出现第二个模态框,不让他们重叠显示。

<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="Info" id="Info">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">模态框一标题</h4>
</div>
<div class="modal-body">
<button type="button" class="ui-button ui-button-small ui-button-outline-primary" data-dismiss="modal">点击按钮</button>
</div>
<!--<div class="modal-footer">-->
<!--<button type="button" class="ui-button ui-button-small ui-button-outline-primary" data-dismiss="modal"-->
<!--aria-label="Close"><span aria-hidden="true">关闭</span></button>-->
<!--</div>-->
</div>
</div>
</div>
  $('#Info').on('hidden.bs.modal', function () {
//模态框关闭时执行
$("#Info2").modal({
keyboard: false,
show:true
});
});

给按钮上绑定data-dismiss="modal"属性,当点击按钮的时候,执行关闭操作,然后将第二个模态框打开。

现在新的需求是点击可查看图片详情,关闭图片详情还需要继续回到之前的模态框,进行其他的操作(如下图所示),所以之前的那种解决方案不再适用,必须要实现模态框的叠加。

<p class="m2">查看图片</p>
//第二层预览图片的模态框
<div id="secondmodal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
<div class="modal-dialog modal-sm2" role="document">
<div class="modal-content">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<div class="modal-body">
<div class="icon-"><img src="/assets/app/images/yulan.png" alt="1"></div>
</div>
</div>
</div>
</div>
  $('.m2').on("click", function () {
$('#secondmodal').modal();
});

好像这种层叠的模态框会使背景颜色不断叠加变深的,这种好像是通过修改控制背景颜色的class和js方法便可解决。(没有去试过)

Bootstrap多层模态框modal嵌套问题的更多相关文章

  1. 黄聪:bootstrap中模态框modal在苹果手机上会失效

    bootstrap中模态框在苹果手机上会失效 可将代码修改为<a  data-toggle="modal" data-target="#wrap" hre ...

  2. Bootstrap使用模态框modal实现表单提交弹出框

    Bootstrap 模态框(Modal)插件 模态框(Modal)是覆盖在父窗体上的子窗体.通常,目的是显示来自一个单独的源的内容,可以在不离开父窗体的情况下有一些互动.子窗体可提供信息.交互等.如果 ...

  3. 黄聪:bootstrap的模态框modal插件在苹果iOS Safari下光标偏离问题解决方案

    一行CSS代码搞定: body.modal-open { position: fixed; width: 100%; }

  4. Bootstrap中模态框多层嵌套时滚动条问题

    在使用Bootstrap中模态框过程中,如果出现多层嵌套的时候,如打开模态框A,然后在A中打开模态框B,在关闭B之后,如果A的内容比较多,滚动条会消失,而变为Body的滚动条,这是由于模态框自带的遮罩 ...

  5. bootstrap模态框modal使用remote第二次加载显示相同内容解决办法

    bootstrap模态框modal使用remote动态加载内容,第二次加载显示相同内容解决办法 bootstrap的modal中,使用remote可以动态加载页面到modal-body中,并弹窗显示 ...

  6. Bootstrap(v3.2.0)模态框(modal)垂直居中

    Bootstrap(v3.2.0)模态框(modal)垂直居中方法: 在bootstrap.js文件900行后面添加如下代码,便可以实现垂直居中. that.$element.children().e ...

  7. Bootstrap 实例 - 模态框(Modal)插件

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. Bootstrap历练实例:模态框(Modal)插件

    模态框(Modal)是覆盖在父窗体上的子窗体.通常,其目的是显示来自一个单独源的内容,可以在不离开父窗体的情况下进行一些交互,子窗体提供一些交互或信息. <!DOCTYPE html>&l ...

  9. Bootstrap 3 模态框播放视频

    Bootstrap 3 模态框播放视频 I'm trying to use the Modal feature from Bootstrap 3 to show my Youtube video. I ...

随机推荐

  1. 51nod 1267二分+优化试验场

    最初,最开始的时候,万能的学姐曾经警告过我们,千万别用什么老狮子MAP,手撸map或者字典树...当时不甚理解...今天...这题直接卡掉了我的MAP,但是使用朴素方法进行二分...不加优化,,都不需 ...

  2. 多进程的基本使用--multiprocessing 【转】

    multiprocessing 如果你打算编写多进程的服务程序,Unix/Linux无疑是正确的选择.由于Windows没有fork调用,难道在Windows上无法用Python编写多进程的程序? 由 ...

  3. java NIO简介

    1)java nio简介 nio 是 java New IO 的简称,在 jdk1.4 里提供的新 api . Sun 官方标榜的特性如有:为所有的原始类型提供 (Buffer) 缓存支持:字符集编码 ...

  4. oracle JOB 查询 添加 修改 删除

    -------------查询JOB----------------- select job, what, next_date, next_sec, sysdate, failures, broken ...

  5. 【Reverse Nodes in k-Group】cpp

    题目: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list ...

  6. Windows下MySQL8.0.11.0安装教程

    1.mysql下载地址:https://dev.mysql.com/downloads/installer/ 2.下载安装MySQL 8.0.11.0 https://cdn.mysql.com//D ...

  7. Cannot set property 'innerHTML' of null 问题的解决

    错误第一次写web 前端代码,出现了“Cannot set property ‘innerHTML’ of null”的错误代码,然后不知道原因在哪? 解决方案在网上查了下资料,原来是js 代码从上往 ...

  8. MongoDB01——安装MangoDB

    一.MongoDB的下载 到MongoDB的官网——https://www.mongodb.com/download-center/community,选择要下载的版本,点击Download 二.安装 ...

  9. Linux下MySQL c++ connector示例

    最近在学习数据库的内容,起先是在windows下用mysql c++ connector进行编程,之所以选用c++而不是c的api,主要是考虑到c++ connector是按照JDBC的api进行实现 ...

  10. 201621123034 《Java程序设计》第2周学习总结

    1. 本周学习总结 本周学习了基本数据类型.包装类,自动装箱与自动拆箱.数组.ArrayList.包装类可以更加方便的转换基本数据类型,而其存放的是对象的引用,而非对象本身,在对其内容进行比较时,要使 ...