简体   繁体   English

Bootstrap 4 Modal仅运行一次

[英]Bootstrap 4 Modal only runs once

So for some reason, I created two modals. 因此出于某种原因,我创建了两个模态。 However, when I open either of them the first time, and then close the modal it will no longer open either of the two when I do t he action that worked the first time. 但是,当我第一次打开它们中的任何一个,然后关闭该模态时,当我第一次执行该操作时,它将不再打开这两个中的任何一个。

在此处输入图片说明 here is my javascript: 这是我的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>

with

$(this).empty();

you are removing all the html inside the modal, so you'll not have the html displayed on the next click 您将删除模式中的所有html,因此下次单击时将不会显示html

I suggest to append the data on a particular id / class name and just empty that id and not the whole modal 我建议将数据附加到特定的ID /类名称上,然后仅将该ID而不是整个模式填充为空

like: 喜欢:

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

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

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