从MySQL获取图像到Bootstrap模态

时间:2016-07-31 02:24:27

标签: jquery mysql twitter-bootstrap

我在1个帖子中有2-5张图片,当我点击Bootstrap模态时,我想显示所有帖子的所有图像。

<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        ALL IMAGES WILL SHOW HERE
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>

1 个答案:

答案 0 :(得分:0)

Using jquery

=============

  1. 为您的模态启动按钮添加ID,例如id =&#34; show&#34;
  2. 添加以下jquery代码以将图像添加到模态

    $("#show").on("click", function() {$(".modal-body").html("<img src='https://static.pexels.com/photos/54278/pexels-photo-54278.jpeg' width='80px'><img src='https://static.pexels.com/photos/51397/legs-window-car-dirt-road-51397.jpeg'  width='80px'><img src='https://static.pexels.com/photos/21014/pexels-photo.jpg'  width='80px'>"    );  })
    
  3. View Demo