简体   繁体   English

如何使用单个模式显示多个图像

[英]how to use a single modal for displaying multiple images

as per the database table rows. 根据数据库表行。 My page will be populated with multiple rows(currently 32) Each row has an image. 我的页面将填充多行(当前为32行),每一行都有一个图像。 I have created a button/link at the nd of each row. 我在每行的nd创建了一个按钮/链接。 I need a popup (#modal) displaying the image fetching from database. 我需要一个弹出窗口(#modal),显示从数据库中获取的图像。 as the button is clicked. 单击该按钮。

I want a particular image fetched from the database table using id passed(id given when clicked link) and displayed under the image tag in popup. 我想使用通过的id(单击链接时给出的id)从数据库表中获取特定的图像,并显示在弹出窗口中的image标签下。 Any way out? 有什么办法吗? I have my code below I NEED to use ONE modal for displaying various images; 我需要在下面的代码中使用一种模式来显示各种图像; fetching on time?? 准时取货? I am confused over it. 我对此感到困惑。 but i know there is way out. 但是我知道有出路。 I am sorry if I am not clear. 如果不清楚,对不起。

 // there will be many links depending on the no. of rows in database <a href="#checkImage" data-toggle="modal"> Image </a> <div class="modal fade" id="checkImage" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <h4 class="modal-title" style="color:black;" id="myModalLabel">Reset Password</h4> </div> <div class="modal-body" style="color:black;"> <h1>Your Image</h1> <img src=#fetchedImageFromDB> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> 

You can use another data attribute to your anchor. 您可以将另一个数据属性用于锚点。

<a href="#checkImage" data-toggle="modal" data-myimage="imageurl.jpg">  Image </a>

Then, in your modal, get the "myimage" (not use Uppercase character to avoid compatibility issues) value and put it inside your modal. 然后,在模态中,获取“ myimage”(不使用大写字符以避免兼容性问题)值,并将其放在模态中。 Your Javascript library should help you. 您的Javascript库应该可以为您提供帮助。

It should work... 应该可以...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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