html - 如何在一页中实现两个模态对话?

标签 html twitter-bootstrap

我的网页中有两个模态对话,使用 Twitter-bootstrap,但只有其中一个有效。

这是代码:

<a href="#format" role="button" class="btn btn-info" data-toggle="format">Phone and Email</a>
<div id="format" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="format" aria-hidden="true">
    <div class="modal-header">
    <!--This needs a fancy phone icon and so does the button.-->
    <img src="img/numberheader.png" alt="">
    </div>
    <div class="modal-body">
    <p>
    <h4>Office:</h4>
    123 4567<br>
    <h4>Programme Manager:</h4>
    765 4321<br>
    <hr>
    <img src="img/emailheader.png" alt="">
    <h4>Email us</h4>Iremovedthemailaddresses<br>
    <a href="Iremovedthemailaddresses" class="btn-primary btn-small">Click Here To Email Us</a>
    <br>
    </p>
    </div>
    <div class="modal-footer">
    <button class="btn btn-info" data-dismiss="modal" aria-hidden="true">Close</button>
    </div>
    </div>
<a href="#myModal" role="button" class="btn btn-info" data-toggle="modal">Phone and Email</a>
<div id="myModal" class="modal hide fade" tabindex="-1"
role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<!--This needs a fancy phone icon and so does the button.-->
<img src="img/numberheader.png" alt="">
</div>
<div class="modal-body">
<p>
<h4>Office:</h4>
123 4567<br>
<h4>Programme Manager:</h4>
765 4321<br>
<hr>
<img src="img/emailheader.png" alt="">
<h4>Email us</h4>Iremovedthemailaddresses<br>
<a href="Iremovedthemailaddresses" class="btn-primary btn-small">Click Here To Email Us</a>
<br>
</p>
</div>
<div class="modal-footer">
<button class="btn btn-info" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>

两个模式的内容尚未分离成其应有的内容,此时它只是概念证明(因此请忽略内容)。

但是,它仅适用于第二个,不适用于第一个。我该怎么做才能使这两种模式都工作?

最佳答案

确保您的 anchor 标记和模态 ID 是唯一的。

<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

演示:http://jsfiddle.net/uf2UR/

关于html - 如何在一页中实现两个模态对话?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14882051/

相关文章:

javascript - Bootstrap 模态验证 Web 表单 + 仅显示表单

html - 多列无序列表

html - 缺少 CSS 日期选择器图标

html - Bootstrap .jumbotron

html - 拉伸(stretch)图像以适应整个容器宽度的 Bootstrap

javascript - Bootstrap 中的进度条跳动且不准确? (包括 fiddle 示范)

javascript - 使用 getElementById 更改 html 内容

html - 在不影响布局的情况下使内联链接的可点击区域更大

html - 背景图像 CSS 的最大尺寸

html - 如何在 CSS 中设置 div 的内边距