打开具有不同内容的 modalbox

麦克鸭4

我制作了一个引导模式框。modalbox 应包含不同的内容,具体取决于单击的链接。到目前为止,我所做的代码打开了相同的内容,但标题正在工作 你可以在这里看到一个 JsFiddle

目前,内容文本在两个框中都被调用。这意味着隐私政策和 cookie 政策都在这两个框中。

  • 如何让链接隐私政策只打开@Text for Privacy Privacy 的文本?
  • 如何让链接 Cookie 政策只打开 Cookie 政策的@Text 文本?

HTML

<div class="container-fluid">
    <div class="row">
        <div class="col-md-3">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <h3 class="panel-title">GENERAL</h3>
                </div>
                <div class="panel-body">
                    <a href="#" data-toggle="modal" data-target="#exampleModal" data-whatever="Privatpolitik">Privacy Policy</a><br/>
                    <a href="#" data-toggle="modal" data-target="#exampleModal" data-whatever="Cookie-Politik">Cookie Policy</a><br/>
                    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                                    <h4 class="modal-title" id="exampleModalLabel">Privatpolitik</h4>
                                </div>
                                <div class="modal-body">@Text for Privacy Policy
                                    <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
                                      <div class="modal-dialog modal-lg" role="document">
                                        <div class="modal-content">
                                          Shouldn´t the modal content text be here?
                                        </div>
                                      </div>
                                    </div>
                                    <div class="modal-body">@Text for Cookie Policy
                                        <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
                                          <div class="modal-dialog modal-lg" role="document">
                                            <div class="modal-content">
                                              Shouldn´t the modal content text be here?
                                            </div>
                                          </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-primary" data-dismiss="modal">Luk</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

南迪塔·夏尔马

将相同的 id 添加到使用中的 modal-bodydata-whatever=""并使用此 js

modal.find('.modal-content .modal-body').hide();
modal.find('.modal-content #' + recipient).show();

还要检查更新的 html,它有问题,所以我也修复了它。2 个modal-bodydiv 必须彼此平行。

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Example of Bootstrap 3 Modal Events</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


</head>

<body>
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-3">
        <div class="panel panel-primary">
          <div class="panel-heading">
            <h3 class="panel-title">GENERAL</h3>
          </div>
          <div class="panel-body">
            <a href="#" data-toggle="modal" data-target="#exampleModal" data-whatever="Privatpolitik">Privacy Policy</a><br/>
            <a href="#" data-toggle="modal" data-target="#exampleModal" data-whatever="Cookie-Politik">Cookie Policy</a><br/>
            <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
              <div class="modal-dialog" role="document">
                <div class="modal-content">
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">&times;</span>
                                        </button>
                    <h4 class="modal-title" id="exampleModalLabel">Privatpolitik</h4>
                  </div>
                  <div class="modal-body" id="Privatpolitik">Text for Privacy Policy
                  </div>
                  <div class="modal-body" id="Cookie-Politik">Text for Cookie Policy
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-primary" data-dismiss="modal">Luk</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <script type="text/javascript">
    $('#exampleModal').on('show.bs.modal', function(event) {
      var button = $(event.relatedTarget) // Button that triggered the modal
      var recipient = button.data('whatever') // Extract info from data-* attributes
      // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
      // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
      var modal = $(this)
      modal.find('.modal-title').text(' ' + recipient)
      modal.find('.modal-content .modal-body').hide();
      modal.find('.modal-content #' + recipient).show();
    })
  </script>
</body>

</html>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在 ListView 上打开具有不同信息的相同片段

来自分类Dev

typo3 modalbox的关闭按钮

来自分类Dev

jQuery手风琴多重打开具有不同的背景颜色

来自分类Dev

如何在CasperJS中打开具有相同标题的不同弹出窗口?

来自分类Dev

关闭Postgre DB连接,并在轨道上打开具有不同DB ruby的新连接

来自分类Dev

Android:Searchview甚至会打开具有不同ID的其他菜单项的onClick

来自分类Dev

Android:Searchview甚至会打开具有不同ID的其他菜单项的onClick

来自分类Dev

创建href,以打开具有特定地址的Google地图

来自分类Dev

使用Python hidapi打开具有多种用途的设备

来自分类Dev

如何打开具有可修改的文件

来自分类Dev

打开具有变量名的文件

来自分类Dev

访问 VBA 以打开具有 SSO 要求的网页

来自分类Dev

打开具有特定模式的URL时打开iOS应用

来自分类Dev

单击通知前先打开具有Parse打开的通知

来自分类Dev

当打开具有特定模式的URL时,打开iOS应用

来自分类常见问题

如何以编程方式快速打开具有坐标的地图App?

来自分类Dev

如何在erlang中打开具有相关路径的文件?

来自分类Dev

使用Mootools打开具有特定大小的目标_blank窗口

来自分类Dev

如何在C ++中打开具有相对路径的文件?

来自分类Dev

打开具有多个内部Intent的应用程序,然后等待结果

来自分类Dev

页面加载时打开具有类折叠的Bootstrap 4 div

来自分类Dev

Apache:防止打开具有非pdf扩展名的PDF文件

来自分类Dev

如何打开具有范围,单个单元格和/或直接输入到数组的ParamArray?

来自分类Dev

在浏览器(地址栏)中打开具有php属性设置的php文件

来自分类Dev

打开具有特定尺寸的纵向格式窗口的超链接

来自分类Dev

尝试打开具有可变文件名的文件时,c程序崩溃

来自分类Dev

打开具有特定扩展名的新文件时的默认文本(例如:.cpp)

来自分类Dev

在 C# 中打开具有 Web 布局的 Word 文档

来自分类Dev

如何在VBA中打开具有特定名称的文件夹中的文件?

Related 相关文章

  1. 1

    在 ListView 上打开具有不同信息的相同片段

  2. 2

    typo3 modalbox的关闭按钮

  3. 3

    jQuery手风琴多重打开具有不同的背景颜色

  4. 4

    如何在CasperJS中打开具有相同标题的不同弹出窗口?

  5. 5

    关闭Postgre DB连接,并在轨道上打开具有不同DB ruby的新连接

  6. 6

    Android:Searchview甚至会打开具有不同ID的其他菜单项的onClick

  7. 7

    Android:Searchview甚至会打开具有不同ID的其他菜单项的onClick

  8. 8

    创建href,以打开具有特定地址的Google地图

  9. 9

    使用Python hidapi打开具有多种用途的设备

  10. 10

    如何打开具有可修改的文件

  11. 11

    打开具有变量名的文件

  12. 12

    访问 VBA 以打开具有 SSO 要求的网页

  13. 13

    打开具有特定模式的URL时打开iOS应用

  14. 14

    单击通知前先打开具有Parse打开的通知

  15. 15

    当打开具有特定模式的URL时,打开iOS应用

  16. 16

    如何以编程方式快速打开具有坐标的地图App?

  17. 17

    如何在erlang中打开具有相关路径的文件?

  18. 18

    使用Mootools打开具有特定大小的目标_blank窗口

  19. 19

    如何在C ++中打开具有相对路径的文件?

  20. 20

    打开具有多个内部Intent的应用程序,然后等待结果

  21. 21

    页面加载时打开具有类折叠的Bootstrap 4 div

  22. 22

    Apache:防止打开具有非pdf扩展名的PDF文件

  23. 23

    如何打开具有范围,单个单元格和/或直接输入到数组的ParamArray?

  24. 24

    在浏览器(地址栏)中打开具有php属性设置的php文件

  25. 25

    打开具有特定尺寸的纵向格式窗口的超链接

  26. 26

    尝试打开具有可变文件名的文件时,c程序崩溃

  27. 27

    打开具有特定扩展名的新文件时的默认文本(例如:.cpp)

  28. 28

    在 C# 中打开具有 Web 布局的 Word 文档

  29. 29

    如何在VBA中打开具有特定名称的文件夹中的文件?

热门标签

归档