【问题标题】:Bootstrap open 2 different modal dialogs same pageBootstrap 打开 2 个不同的模态对话框同一页面
【发布时间】:2014-08-06 10:45:00
【问题描述】:

我有一个页面,我想在其中启动 2 个不同的模式窗口。一种用于创建新用户,一种用于编辑现有用户。

我在可点击的表格中显示现有用户并链接到我的模态#edit,如下所示:

<tr  data-id="<?php echo $value['id'];?>" data-toggle="modal" data-target="#edit" class="open-edit">

这将打开我的引导模式对话框:

<div class="modal fade" id="edit">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
I ommited the rest of the code.. I grab this modal on its id="edit".

这就像我想要的那样工作 - 单击表格条目时,模式对话框会打开我创建的表单。

现在我创建了这个模态对话框的精确副本,只是将 id="edit" 更改为 id="create" 并创建了这个按钮:

<button class="btn btn-primary btn-me" data-toggle="modal" data-target="#create" >Create user<i class="fa fa-arrow-circle-right"></i></button>

我认为它现在会简单地打开我的第二个名为 #create 的模态对话框,但它会清空屏幕,就像显示模态对话框时一样 - 但不显示任何模态窗口/对话框。

谁能帮我理解为什么会发生这种情况或我做错了什么?

【问题讨论】:

    标签: php html twitter-bootstrap twitter-bootstrap-3 modal-dialog


    【解决方案1】:

    此代码在同一页面中打开 2 个模式对话框

    <button type="button" class="btn btn-success btn-sm" style="width: 100%;" data-toggle="modal" data-target="#modal1">modal1</button>
    
    <button type="button" class="btn btn-success btn-sm" style="width: 100%;" data-toggle="modal" data-target="#modal2">modal2</button>
    
    <div class="modal hide fade" id="modal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel"></h4>
              </div>
              <div class="modal-body">
    
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Chiudi</button>
              </div>
            </div>
          </div>
        </div>
    
    
    
    <div class="modal hide fade" id="modal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel"></h4>
              </div>
              <div class="modal-body">
    
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Chiudi</button>
              </div>
            </div>
          </div>
        </div>
    

    【讨论】:

    • 发现我有一个奇怪的表单组标签位置,同时试图将我的模式放在你的里面。删除它们后,它可以工作! :) 谢谢!
    • 这是一个很好的信息......但我想知道你是否可以使用一个类而不是一个模态的 id?我有几个按钮可以打开一个模式,还有一个 标签可以打开另一个。我会在按钮上使用类,在 标记上使用 ID。这适用于您上面的代码吗?
    • 仔细检查模态 div 中的 html。我在第一个模式中有一个结束标记 而不是
      。并且当它是唯一的模态时起作用..当我将其复制粘贴到第二个模态中时,即使在更改了 id 和所有内容之后, first 模态仍然有效,但第二个没有。最后我修复了两个 div 中的标签,现在两个模式都可以工作了。
    【解决方案2】:

    你需要把它放在两个不同的div上,它会起作用,我修好了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多