Twitter Bootstrap - 单击图像以显示模态,具有多个图像和多个模态。

时间:2014-09-21 11:24:04

标签: javascript jquery html twitter-bootstrap

我有9张图片,每张图片需要显示不同的模态。无论我点击哪张图片,它都只显示第一个模态。我可以看到他们都有相同的ID,这可能是我的错误,但我对javascript也不是那么好。总而言之,点击一张图片,显示模态A及其内容,点击另一张图片,显示模态B及其不同的内容。

我只有:

    <script type="text/javascript">$('#myModal').modal('show')</script>

      <div class="modal fade" id="largeModal" tabindex="-1" role="dialog" aria-labelledby="largeModal" aria-hidden="true">
        <div class="modal-dialog modal-lg">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
              <h4 class="modal-title" id="myModalLabel">1</h4>
            </div>
              <div class="modal-body">
                <h1>Select a unit to study.</h1>
                <a href="sit1e" target="_blank">
                  <img src="1.png" class="img-responsive" />
                </a>
                <a href="site2" target="_blank">
                  <img src="2.png" class="img-responsive" />
                </a>
                 <div class="icons">
                <a href="sound"  target="_blank">
                  <img src="audio.png" class="img-responsive" />
                </a>
                <a href="print" target="_blank">
                  <img src="print.png" class="img-responsive" />
                </a>
                <a href="" target="_blank">                    
                  <img src="info.png" class="img-responsive" />
                </a>
                <a href="" target="_blank">
                  <img src="link.png" class="img-responsive" />
                </a>
                </div>
              </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
          </div>
        </div>
      </div>

      <div class="col-md-4 col-sm-4 col-xs-12">
          <a href="#myModal" id="press1b" class="thumbnail" data-toggle="modal" data-target="#largeModal">
            <img src="2.jpg" class="img-responsive"/>
          </a>
      </div>

               <div class="modal fade" id="largeModal" tabindex="-1" role="dialog" aria-labelledby="largeModal" aria-hidden="true">
        <div class="modal-dialog modal-lg">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
              <h4 class="modal-title" id="myModalLabel">1</h4>
            </div>
              <div class="modal-body">
                <h1>Select a unit to study.</h1>
                <a href="sit1e" target="_blank">
                  <img src="1.png" class="img-responsive" />
                </a>
                <a href="site2" target="_blank">
                  <img src="2.png" class="img-responsive" />
                </a>
                 <div class="icons">
                <a href="sound"  target="_blank">
                  <img src="audio.png" class="img-responsive" />
                </a>
                <a href="print" target="_blank">
                  <img src="print.png" class="img-responsive" />
                </a>
                <a href="" target="_blank">                    
                  <img src="info.png" class="img-responsive" />
                </a>
                <a href="" target="_blank">
                  <img src="link.png" class="img-responsive" />
                </a>
                </div>
              </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
          </div>
        </div>
      </div>

1 个答案:

答案 0 :(得分:0)

      <div class="col-md-4 col-sm-4 col-xs-12">
          <a href="#myModal" id="press1b" class="thumbnail" data-toggle="modal" data-target="#largeModal">
            First Modal
          </a>
          <a href="#smallModal" id="press1b" class="thumbnail" data-toggle="modal" data-target="#smallModal">
            Second Modal
          </a>
      </div>
<div class="modal fade" id="largeModal" tabindex="-1" role="dialog" aria-labelledby="largeModal" aria-hidden="true">
        <div class="modal-dialog modal-lg">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
              <h4 class="modal-title" id="myModalLabel">1</h4>
            </div>
              <div class="modal-body">
                <h1>Select a unit to study.</h1>
                FIRST MODAL CONTENT
                </div>
              </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
          </div>
        </div>
      </div>
<div class="modal fade" id="smallModal" tabindex="-1" role="dialog" aria-labelledby="smallModal" aria-hidden="true">
        <div class="modal-dialog modal-lg">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
              <h4 class="modal-title" id="myModalLabel">1</h4>
            </div>
              <div class="modal-body">
                <h1>Select a unit to study.</h1>
                SECOND MODAL CONTENT
                <a href="" target="_blank">
                  <img src="link.png" class="img-responsive" />
                </a>
                </div>
              </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
          </div>
        </div>
      </div>