简体   繁体   中英

How can I have two different Modals in Twitter Bootstrap

So if I have two different Models the content within the second model doesn;t show up instead it's the content of the first model. How can i get two individual Models with different contents

EXAMPLE Model 1:

<!-- Button to trigger modal -->
<a href="#myModal" role="button" class="btn" data-toggle="modal">modal 1</a>

<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Modal header</h3>
  </div>
  <div class="modal-body">
    <p>One fine body…</p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-primary">Save changes</button>
  </div>
</div>

EXAMPLE MODEL 2:

<!-- Button to trigger modal -->
<a href="#myModal" role="button" class="btn btn-danger" data-toggle="modal">modal 2</a>

<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">this is different</h3>
  </div>
  <div class="modal-body">
    <p>this ones different but yet when you click it the content of the first Model appears.</p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">diffent</button>
    <button class="btn btn-danger">Quit</button>
  </div>
</div>

my goal is for when I click on the second modal button for the content to be what is in the second modal and not whats in the first Modal again. I want them both to be different.

Use 2 different modal id's....

<!-- Button to trigger modal -->
<a href="#myModal1" role="button" class="btn" data-toggle="modal">modal 1</a>

<!-- Modal -->
<div id="myModal1" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
...

<!-- Button to trigger modal -->
<a href="#myModal2" role="button" class="btn" data-toggle="modal">modal 2</a>

<!-- Modal -->
<div id="myModal2" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
...

Demo on Bootply: http://bootply.com/80525

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM