简体   繁体   English

如何在Laravel中使用点击动态链接调用动态模式弹出窗口?

[英]How to call dynamic modal pop up on click dynamic link using in laravel?

I have dynamic link and each link is associated with modal pop up. 我有动态链接,每个链接都与模式弹出窗口相关联。

@foreach($image_data as $image)
  <a href="#" data-toggle="modal" data-target="#{{$image->image_id}}">
    <img src="{{asset('public/user_images/')}}/{{$image->image_name}}">
  </a>

  <div class="modal fade" id="{{$image->image_id}}" tabindex="-1" role="dialog">
   <div class="modal-dialog" role="document">
    <div class="modal-content">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">X</span></button>
        <div class="modal-body">
         <img src="{{asset('public/user_images/')}}/{{$image->image_name}}">
        </div>
    </div>
   </div>
  </div>

 @endforeach

What javascript or something else should I use to pop up this model ? 我应该使用什么JavaScript或其他东西来弹出此模型?

$('.buttonClass').on('click', function(){

      $('#modalID').fadeIn();

});

modalID has to be determined by a data-attribute that you can give to your buttons. modalID必须由您可以提供给按钮的数据属性来确定。 For example 例如

<button type="button" class="open" data-dismiss="modal" data-id={{$image->image_id}}>

And then in JavaScript add 然后在JavaScript中添加

$('.buttonClass').on('click', function(){

    let modalID = '#' + $(this).data('id');
    $(modalId).fadeIn();

});

Add class="modal-open" to your a s class="modal-open"到您的a

jQuery method jQuery方法

$('.modal-open').on('click', function() {
  $( '#'+$(this).data('target') ).show();
})

Typing from my head so there could be typos. 从我的头打字,这样可能会有错别字。

If the a s and .modal s are added dynamically then: 如果a.modal被动态添加,则:

$(this).on('click','.modal-open', function() { ...

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

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