Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JQuery获取数据属性表单按钮并在引导模式中显示值_Jquery_Html_Twitter Bootstrap_Laravel_Blade - Fatal编程技术网

使用JQuery获取数据属性表单按钮并在引导模式中显示值

使用JQuery获取数据属性表单按钮并在引导模式中显示值,jquery,html,twitter-bootstrap,laravel,blade,Jquery,Html,Twitter Bootstrap,Laravel,Blade,我在foreach循环中打开一个表单,该循环调用一个引导模式,以便在删除之前为循环中的每个项目显示一个表单以进行确认。我希望类别名称显示在模式中 表格: 当前,模式仅显示for each循环中的第一项,因为 var按钮=$(“按钮[name='delete_modal'])) 不标识所选类别,仅标识列表中的第一项。如何让jquery识别刚刚单击的按钮的数据标题值?尝试使用button.attr('data-title')console.log($(此))应该提供当前单击按钮的详细信息…是日志中的

我在foreach循环中打开一个表单,该循环调用一个引导模式,以便在删除之前为循环中的每个项目显示一个表单以进行确认。我希望类别名称显示在模式中

表格:

当前,模式仅显示for each循环中的第一项,因为

var按钮=$(“按钮[name='delete_modal']))


不标识所选类别,仅标识列表中的第一项。如何让jquery识别刚刚单击的按钮的数据标题值?

尝试使用
button.attr('data-title')
console.log($(此))应该提供当前单击按钮的详细信息…是日志中的类别名称吗?按钮。attr('data-title')给我attr未定义解决方案。log($(此)给我[div#confirm.modal.fade]@RohitasBehera我认为我在这里是个白痴……它给了我[form#[object htmlinputtement].form inline.form delete],其中包含按钮“button.btn.btn sm.btn danger”……我如何在jquery中引用它?试试
button.attr('data-title')
console.log($(这个))应该给出当前点击按钮的详细信息…是日志中的类别名称吗?按钮。attr('data-title')给我attr是未定义的解决方案。log($(这)给我[div#confirm.modal.fade]@RohitasBehera我想我在这里是个白痴…它给了我[form#[object htmlinputtement].form inline.form delete],其中包含按钮作为“button.btn.btn sm.btn danger”…我如何在jquery中引用它?
          <table class='table table-striped' data-form="deleteForm">
            <thead>
                <tr>
                    <th>Name</th>
                    <th width="50px"></th>
                </tr>
            </thead>
            <tbody>
                @foreach($categories as $category)
                <tr>
                    <td><a href="{{ route('categories.show', $category->id) }}">{{ $category->name }}</a></td>
                    <td>
                        {!! Form::model($category, ['method' => 'delete', 'route' => ['categories.destroy', $category->id], 'class' =>'form-inline form-delete']) !!}
          {!! Form::hidden('id', $category->id) !!}
          {!! Form::button('<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>', ['class' => 'btn btn-sm btn-danger', 'name' => 'delete_modal', 'data-title'=>"$category->name"]) !!}
          {!! Form::close() !!}
                    </td>
                </tr>
                @endforeach
            </tbody>
        </table>
<div class="modal fade" id="confirm" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title"></h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-footer">
                <button type="button" class="btn btn-sm btn-danger" id="delete-btn">Delete</button>
                <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
    $('table[data-form="deleteForm"]').on('click', '.form-delete', function(e){
    e.preventDefault();
    var $form=$(this);
    $('#confirm').on('show.bs.modal', function (event) {
                var button = $("button[name='delete_modal']")
                var recipient = button.data('title') // Extract info from data-* attributes
                var modal = $(this)
                modal.find('.modal-title').text('Delete Category: ' + recipient)
            });
    $('#confirm').modal({ backdrop: 'static', keyboard: false })
            .on('click', '#delete-btn', function(){
                    $form.submit();
            });
    });