简体   繁体   English

Bootstrap 4 Ajax加载模式

[英]Bootstrap 4 ajax loaded modal

I am migrating from BS3 to BS4.1 我正在从BS3迁移到BS4.1

In my apps I do use ajax loaded modals. 在我的应用程序中,我确实使用了ajax加载的模态。

In layout I have 在布局中我有

<div class="modal fade" id="myModalToFillInfo" tabindex="-1" role="dialog" aria-labelledby="myModalToFillInfoLabel" aria-hidden="true">
</div>

Then button 然后按

<button type="button" class="btn btn-primary" title="Informace o uživateli" onclick="showUserDetail(@u.Id)" data-toggle="modal" data-target="#myModalToFillInfo">
   <i class="fas fa-info" aria-hidden="true"></i>
</button>

and simple JS func 和简单的JS函数

showUserDetail = function (id) {
    $.get('/Uzivatel/ModalUserInfo/' + id,
        function (data) {
            $('#myModalToFillInfo').html(data);
        });
}

Func load for example this 例如func load

<div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>

So its makes a example modal togather. 因此,它成为模态集合的一个例子。 Thanks to data-toggle and target it auto opens the modal. 多亏了数据切换和目标,它自动打开了模态。

Problem is that close buttons dosen't work. 问题是关闭按钮不起作用。

Same code was working in BS3. 相同的代码在BS3中工作。

Doesn anyone know how to solve this? 有谁知道如何解决这个问题?

we manually close the bootstrap modal like

  <div class="modal" id="AddQueModal">
    <div class="modal-dialog" role="document">
  <div class="modal-content">
  <div class="modal-header">
    <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
    <button type="button" class="close closeModel" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body">
    ...
  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-secondary" data- 
  dismiss="modal">Close</button>
    <button type="button" class="btn btn-primary">Save changes</button>
  </div>
  </div>
  </div>
 </div>

<script>
 $(".closeModel").click(function() {
    $('#AddQueModal').modal('toggle');
 });
</script>

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

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