php 我在foreach模态对话框,并希望提交按钮后显示div动画

t5fffqht  于 5个月前  发布在  PHP
关注(0)|答案(1)|浏览(53)

我在一个表格单元格中有这个,并将#key传递给模态对话框

<td> 
  <a id="myButton" href="#!" data-toggle="modal" data-target="#restoreBackup_{{ $key }}" class="btn btn-warning">Restore Backups</a> 
</td>

字符串
当我点击恢复按钮,然后模态对话框与窗体打开foreach
我的模式:

@foreach ($backups as $key => $backup) 
  {{-- //restore section--}}
<div class="modal fade" id="restoreBackup_{{ $key }}" tabindex="-1" role="dialog" aria-labelledby="restoreBackup_{{ $key }}" aria-hidden="true">

  <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">{{ translate('Confirm Restore') }}</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="alert alert-warning" role="alert">
        <b>Do you really want to restore this backup? {{ $key }}</b>
      </div>
      <form id="frm_restore_{{ $key }}" action="{{ route('backups.restore') }}" method="POST">
        @csrf
        <input type="hidden" name="key" value="{{ $key }}" />
        <input type="hidden" name="backuptype" value="{{ $backup['type'] }}" />
        <div class="modal-body">
        @if ($backup['type'] == 0)
          <div class="form-group">
            <h5 class="modal-title">Choose Your Restore Type</h5>
          </div>
          <div class="radio-button">
            <input type="radio" id="radio30" name="restoretype" value="0" checked>
            <label for="radio30">DataBase And Folder</label>
            <input type="radio" id="radio31" name="restoretype" value="1">
            <label for="radio31">Only DataBase</label>
            <input type="radio" id="radio32" name="restoretype" value="2">
            <label for="radio32">Only Folder</label>
          </div>
        @endif
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
            <button type="submit" class="btn btn-warning">Restore</button>
          </div>
        </div>
      </form>
      <div id="animationdiv_{{ $key }}"></div>
    </div>
  </div>
</div>
@endforeach


正如你所看到的,我有一个这样的div:

<div id="animationdiv_{{ $key }}"></div>


我有一个css代码,其中定义了动画:

.currently-loading {
        opacity: 0.75;
        -moz-opacity: 0.75;
        filter: alpha(opacity=75);
        background-image: url({{ static_asset('backup_restore_loading.gif') }});
        background-repeat: no-repeat;
        position: absolute;
        height: 100%;
        width: 100%;
        z-index: 10;
        background-size: contain;
    }


如果我在foreach循环外打开一个对话框模式,例如它的表单名称是frm_backup,那么如果我使用以下代码提交它,我可以在JavaScript部分中显示动画:

var frm_backup = document.getElementById('frm_backup');
frm_backup.addEventListener('submit', bmdLoading1);

//display loading message
function bmdLoading1() {
    var divloading1 = '';
    divloading1 = '<div class="currently-loading"></div>'
    $("#animation").html(divloading1);
}


但是在我在foreach循环中打开一个对话框模态的情况下,我不知道如何传递$key并使用$key显示div动画,在这种情况下,每个模态都有一个像id=“frm_restore_{{ $key }}”这样的名称,每个div都有一个像id=“animationdiv_{{ $key }}”这样的名称。

bvjveswy

bvjveswy1#

这取决于你想把动画“div”添加到哪个元素。但是你必须编辑html。你用你想显示的div创建了一个变量,但是你没有把它赋值给代码中的任何位置。比如

$('#modal-body').html(divloading1);

字符串

相关问题