.modal('dispose')有什么作用?引导程序4 [英] What does .modal('dispose') do? Bootstrap 4

查看:78
本文介绍了.modal('dispose')有什么作用?引导程序4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档, .modal('dispose') ,破坏模式.

According to the documentation the .modal('dispose'), destroys the modal.

.modal('dispose')

销毁元素的模态.

但是当我使用

$('#myModal').on('hidden.bs.modal', function (event) {
    // Destroy modal
    $('#myModal').modal('dispose');
});

模态仍然是文档的一部分.文档使我感到困惑,这种方法不用于从文档中删除模式吗?这种方法的目的是什么?

The modal is still part of the document. The documentation confuses me, is this method not used to remove the modal from the document? What is the purpose of this method?

$('#myModal').modal('show');

$('#myModal').on('hidden.bs.modal', function (event) {
  console.log('Destroy modal');
  $('#myModal').modal('dispose');
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js" integrity="sha384-u/bQvRA/1bobcXlcEYpsEdFVK/vJs3+T+nXLsBYJthmdBuavHvAW6UsmqO2Gd/F9" crossorigin="anonymous"></script>
<div class="modal" tabindex="-1" role="dialog" id="myModal">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">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">
        <p>Modal body text goes here.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary">Save changes</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

推荐答案

它破坏了Bootstrap的Modal组件的jQuery实例.它不会从DOM中删除模式标记.

It destroys the jQuery instance of the Bootstrap's Modal component. It doesn't remove the Modal markup from the DOM.

这篇关于.modal('dispose')有什么作用?引导程序4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆