【发布时间】:2017-05-28 07:58:59
【问题描述】:
我需要一些建议来动态显示图像。
我目前正在使用 W3Schools 示例中的此脚本:
http://www.w3schools.com/howto/howto_css_modal_images.asp
这是脚本:
<script>
// Get the modal
var modal = document.getElementById('myModal');
// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById('myImg');
var modalImg = document.getElementById("img");
var captionText = document.getElementById("caption");
img.onclick = function(){
modal.style.display = "block";
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
</script>
@foreach($properties->files as $file)
<div class="col-md-6 thumb">
<a class="thumbnail">
<img id="myImg" src="{{ URL::asset('uploads/products/' . $file->name) }}" alt="{{ $file->name }}" width="300" height="200">
</a>
</div>
<div id="myModal" class="modal">
<span class="close" onclick="document.getElementById('myModal').style.display='none'">×</span>
<img class="modal-content" id="img">
<div id="caption"></div>
</div>
@endforeach
我需要在缩略图中显示动态显示的图像,因为只显示列表中的第一张图像。
在视图中,图像显示如下:
第一个图像显示在模态视图中,但第二个没有:
这是我在 Propertycontroller 中的 show 方法:
Public function show ($ id)
{
$ Properties = Property :: find ($ id);
$ Files = File :: where ('property_id', $ properties-> id) -> get ();
Return view ('properties.show', compact ('properties', 'files'));
}
此要求与:
Show image file by id in Laravel 5.2
单击图像时如何在模态视图中显示图像?
【问题讨论】:
标签: javascript php mysql laravel laravel-5.2