Twitter bootstrap remote modal shows same content every time

前端 未结 22 1259
春和景丽
春和景丽 2020-11-22 12:29

I am using Twitter bootstrap, I have specified a modal

<
22条回答
  •  悲&欢浪女
    2020-11-22 13:09

    For Bootstrap 3, in modal.js I changed:

    $(document)
      .on('show.bs.modal',  '.modal', function () { $(document.body).addClass('modal-open') })
      .on('hidden.bs.modal', '.modal', function () { $(document.body).removeClass('modal-open'); })
    

    to

    $(document)
      .on('show.bs.modal',  '.modal', function () { $(document.body).addClass('modal-open') })
      .on('hidden.bs.modal', '.modal', function () { 
        $(this).removeData('bs.modal').empty()
        $(document.body).removeClass('modal-open')
      })
    

    (extra spacing added for clarity)

    This prevents any unwanted flash of old modal content by calling empty() on the modal container as well as removing the data.

提交回复
热议问题