为什么我的模态体中没有值传递?

问题描述 投票:0回答:1

例如,有三个输入样本,当我尝试删除第二个输入样本时,它将不会被删除,而第三个将被删除。另一个错误是,如果剩下一个输入的样本,我尝试删除它,那么代码将是错误的。

模态代码

<div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
    <div class="modal-content">
        <div class="modal-header">

        <h1 class="modal-title text-center" id="myModalLabel">Delete Confirmation</h1>
        </div>

       <form class ="delete" action="{{ action('ReservationController@destroy', ['id' => $reservation->id])}}" method="post">


        {{ method_field('DELETE')}}
        {{ csrf_field() }}

        <div class="modal-body">
            <p class="text-center">Are you sure you want to delete?
            </p>
            <input type="hidden" name="reservation_id" id="resid" value="" />
        </div>
        <div class="modal-footer">

            <button type="button" class="btn btn-success" data-dismiss="modal">No, Close</button>
            <button type="submit" class="btn btn-danger">Yes, Delete</button>

        </div>
        </form>
    </div>
</div>

脚本代码

<script>
    $('#delete').on('show.bs.modal',function(event){
    var button = $(event.relatedTarget)
    var resid = button.data('deleteid')
    var modal = $(this)

    modal.find('.modal-body #resid').val(resid)
    })
    </script>

按钮代码

<button type="submit" class="btn btn-danger" data-deleteid="{{$reservation->id}}" data-toggle="modal" data-target="#delete" >Delete</button>

调节器

$reservation = PropertyReservation::findOrFail($id);
    $reservation->delete();

    return redirect('/reservations')->with('success','Successfully Deleted');
javascript php laravel modal-dialog
1个回答
0
投票

试试这个

<script>
$(document).on('show.bs.modal','#delete',function(event){
   var resid = $(this).find('button[type="submit"]').attr('data-deleteid')
   var modal = $(this);

   modal.find('.modal-body #resid').val(resid);
})
</script>
© www.soinside.com 2019 - 2024. All rights reserved.