简体   繁体   English

如何将图像,标题和描述传递给Bootstrap Modal弹出窗口?

[英]How to pass image,title and description to Bootstrap Modal popup?

How i can pass image,title and description to bootstrap modal? 我如何将图像,标题和描述传递给引导模态? when one image link click the modal open with that image title and description. 当一个图像链接单击带有该图像标题和描述的模式打开时。 my code is: 我的代码是:

<?php                     
$result = mysql_query("SELECT * FROM project");

           $file_path = 'admin1\projectimages/';


while($post=mysql_fetch_array($result)){    
$id=$post['id'];
$ptitle=$post['Title'];
$image=$post['Image'];
$des=$post ['Description'];

$src = $file_path . $post['Image'];
echo'<li class="col-md-4 col-sm-6"><a href="#modal" class="fa" data-toggle="modal"  data-placement="right"><h4 class="project_heading">'.$ptitle.'</h4></a>
                    <a href="#modal" class="fa ok " data-toggle="modal"  data-target="#modal" data-placement="right"><img src='.$src.' style="width:250px; border:1px solid red;"></a></li>';}
?>

Modal Code: 模态代码:

<div class=" modal fade bs-example-modal-lg"  role="dialog"  id="modal" aria-hidden="true" data-keyboard="true" data-backdrop="static" tabindex="-1">
    <a href="#modal" class="fa fa-times cls-pop" data-dismiss="modal" id="thanks" ></a>
    <div class="modal-dialog modal-lg clearfix">
      <div class="modal-content pop-up">
<h3 >Title</h3>
               <div class="clearfix">
            <div>
              <img src="   "   style="width:99%; border:1px solid red;">
              <p></p><p ></p>
<p></p></div>

        </div>


      </div>
    </div>
  </div>

You can pass data from PHP to HTML by using echo . 您可以使用echo将数据从PHP传递到HTML。

So here: <h3 >Title</h3> 所以在这里: <h3 >Title</h3>

you would put: <h3><?PHP echo $ptitle; ?></h3> 您应该输入: <h3><?PHP echo $ptitle; ?></h3> <h3><?PHP echo $ptitle; ?></h3>

The shorter notation for this is <?= $ptitle; ?> 较短的表示法是<?= $ptitle; ?> <?= $ptitle; ?>

It will work just fine as long as 1) your HTML is working and 2) your variables are getting populated. 只要1)您的HTML正常运行,以及2)填充变量,它就可以正常工作。

Set image src in tag 在标签中设置图片src

<li>
 <a href="#modal" class="fa open_model" data-toggle="modal"  data-placement="right"><h4 class="project_heading" data-imgsrc="'.$src.'" data-desc="'.$ptitle.'">'.$ptitle.'</h4>
</a>
<a href="#modal" class="fa ok open_model" data-toggle="modal"  data-target="#modal" data-placement="right" data-imgsrc="'.$src.'" data-desc="'.$ptitle.'">

In your model html 在您的模型html中

<div class="modal-content pop-up">
 <h3>Title</h3>
 <div class="clearfix">
 <div>
  <img id="model_img" src="" style="width:99%; border:1px solid red;">
  <p></p><p ></p><p></p>
 </div>

When you click on the link set the image src and description to model set in your js file 当您单击链接时,将图像src和描述设置为js文件中的模型集

$(document).on("click", ".open_model", function () {
     var imgSrc = $(this).data('imgsrc');
     var desc = $(this).data('desc');
     $(".modal-content #model_img").attr('src',imgSrc);
});

If you set it well than it will works 如果设置得好,它将起作用

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

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