Twitter bootstrap remote modal shows same content every time

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

I am using Twitter bootstrap, I have specified a modal

<
相关标签:
22条回答
  • 2020-11-22 13:05

    Adding an $(this).html(''); to clear visible data as well, and it works pretty fine

    0 讨论(0)
  • 2020-11-22 13:09

    This works with Bootstrap 3 FYI

    $('#myModal').on('hidden.bs.modal', function () {
      $(this).removeData('bs.modal');
    });
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-11-22 13:09
    $('body').on('hidden.bs.modal', '.modal', function () {
           $("#mention Id here what you showed inside modal body").empty()
    });
    

    Which html element you want to empty like(div,span whatever).

    0 讨论(0)
  • 2020-11-22 13:12

    This one works for me:

    modal

    <div class="modal fade" id="searchKaryawan" tabindex="-1" role="dialog" aria-labelledby="SearchKaryawanLabel" aria-hidden="true"> <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="SearchKaryawanLabel">Cari Karyawan</h4>
      </div>
      <div class="modal-body">
        <input type="hidden" name="location">
        <input name="cariNama" type="text" class="form-control" onkeyup="if (this.value.length > 3) cariNikNama();" />
        <div class="links-area" id="links-area"></div>
      </div>
      <div class="modal-footer">
      </div>
    </div> </div></div>
    

    script

    <script type="text/javascript">$('body').on('hidden.bs.modal', '.modal', function () {  $(".links-area").empty() }); </script>
    

    links-area is area where i put the data and need to clear

    0 讨论(0)
  • 2020-11-22 13:12

    Tested on Bootstrap version 3.3.2

      $('#myModal').on('hide.bs.modal', function() {
        $(this).removeData();
      });
    
    0 讨论(0)
提交回复
热议问题