【问题标题】:Bootstrap 4 Modal only runs onceBootstrap 4 Modal 只运行一次
【发布时间】:2018-11-28 11:39:29
【问题描述】:

因此,出于某种原因,我创建了两个模态。但是,当我第一次打开它们中的任何一个,然后关闭模式时,当我执行第一次有效的操作时,它将不再打开两者中的任何一个。

这是我的javascript:

<script>
   $(document).ready(function()
   {
     $("#accountsTable").tablesorter();

     $('#newAccount').on('click', function() {
        $.ajax({
         async:true,
         url: '/crm/accounts/create_account_modal',
         success: function(res)
         {
            $('.createAccountModalBody');
            alert(res);
            $('#createAccountModal').modal({show:true});
            $('.createAccountModalBody').html(res);

         }});
    });

    $('tr').on('dblclick', function() {
       var AccountID = $(this).find('td').first().html();
       alert(AccountID);
       $('.editAccountModalBody').load('/crm/accounts/edit_account/1');

       $('#editAccountModal').modal('show');
    });

      $('#editAccountModal').on('hidden.bs.modal', function () {
                $(this).removeData('bs.modal');
                $(this).empty();
                $(this).removeAttr('style');
      });
        $('#createAccountModal').on('hidden.bs.modal', function () {
                $(this).removeData('bs.modal');
                $(this).empty();
                $(this).removeAttr('style');
      });

   });

   $('tr').on('dblclick', function() {
       var AccountID = $(this).find('td').first().html();
        alert(AccountID);
       $('.editAccountModalBody').load('/crm/accounts/create_account_modal');

       $('#editAccountModal').modal('show');
    });

</script>

【问题讨论】:

    标签: javascript django twitter-bootstrap bootstrap-4


    【解决方案1】:

    $(this).empty();
    

    您将删除模态框内的所有 html,因此下次单击时不会显示 html

    我建议将数据附加到特定的 id/类名上,然后清空该 id 而不是整个模态

    喜欢:

    $("#editAccountModalDATA").empty();
    

    【讨论】:

    • 我设法通过删除它来修复它: $('#editAccountModal').on('hidden.bs.modal', function () { $(this).removeData('bs.modal '); $(this).empty(); $(this).removeAttr('style'); }); $('#createAccountModal').on('hidden.bs.modal', function () { $(this).removeData('bs.modal'); $(this).empty(); $(this). removeAttr('style'); });
    猜你喜欢
    • 2015-04-14
    • 2014-03-31
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多