【问题标题】:Get images from MySQL to Bootstrap modal从 MySQL 获取图像到 Bootstrap 模式
【发布时间】:2016-12-05 10:24:44
【问题描述】:

我在 1 个帖子中有 2-5 张图片,我想在单击引导模式时显示所有帖子的所有图片。

<!-- 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>

【问题讨论】:

  • 一种解决方案可能是获取图像位置的数组,然后将此数组传递给您的模板。现在,当触发对话框时,只需使用 jquery 使用 .html() 从数组中加载图像

标签: jquery mysql twitter-bootstrap


【解决方案1】:
Using jquery

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

  1. 为您的模态启动按钮指定一个 ID,例如 id="show"
  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'>"    );  })
    

View Demo

【讨论】:

    猜你喜欢
    • 2016-10-11
    • 1970-01-01
    • 2012-09-03
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多