首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel 8- jQuery模态数据未显示

Laravel 8- jQuery模态数据未显示
EN

Stack Overflow用户
提问于 2021-03-05 15:07:51
回答 1查看 153关注 0票数 0

我正在尝试通过删除确认模式获取location_name,但它没有返回任何结果。

删除按钮:

代码语言:javascript
复制
<li>
    <a href="" class="remove" data-id="{{ $location->id }}" data-location_name="{{ $location->location_name }}" data-toggle="modal" data-target="#delete-modal">
    <span data-feather="trash-2"></span></a>
</li>

删除模式:

代码语言:javascript
复制
{{-- Modal Delete --}}
<div class="modal-info-delete modal fade show" id="delete-modal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm modal-info" role="document">
        <div class="modal-content">
            <form action=" {{ route('worklocations_table.destroy',$location->id) }} " method="post">
            {{ method_field('delete') }}
            {{ csrf_field() }}
            {{-- Modal Body --}}
            <div class="modal-body">  
                <div class="atbd-notice__content">
                    <div class="atbd-notice__top text-center mt-20">
                        <div class="atbd-notice__icon bg-danger">
                            <i class="fas fa-exclamation color-white"></i>
                        </div>
                        <div class="atbd-notice__text">
                            <p>Are you sure you want to delete this location?</p>
                            <div class="mt-15">
                            <h4>Location Name</h4>
                                <input type="text" class="form-control" id="id" name="id">
                                <input type="text" class="form-control" id="location_name" name="location_name">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            {{-- Modal Buttons --}}
            <div class="modal-footer d-flex justify-content-center">
                <button type="submit" class="btn btn-default btn-squared btn-outline-primary">Yes, delete</button>          
                <button type="button" class="btn btn-default btn-squared btn-outline-light" data-dismiss="modal">No</button>         
            </div>
            
            </form>
        </div>
    </div>
</div>
{{-- Modal Delete - End --}}

JS jQuery:

代码语言:javascript
复制
<script>

    $('#delete-modal').on('show.bs.modal', function(event){

        var button = $(event.relatedTarget)
        var id = button.data('id')
        var location_name = button.data('location_name')
        var modal = $(this)
        modal.find('modal-body #id').val(id);
        modal.find('modal-body #location_name').val(location_name);
    })

</script>

结果:

模态deos未显示数据

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-05 19:00:32

丢失的点(.)有一个错误对于类模式-当您使用modal.find时,对于'JS jQuery‘代码中的两个值。我写这篇评论是为了让你看看它在哪里以及它发生的原因。

代码语言:javascript
复制
<script>

    $('#delete-modal').on('show.bs.modal', function(event){

        var button = $(event.relatedTarget)
        var id = button.data('id')
        var location_name = button.data('location_name')
        var modal = $(this)
        // The find function below will not be able to select that 
        // because "modal-body" is not a valid class selector
        modal.find('modal-body #id').val(id);
        modal.find('modal-body #location_name').val(location_name);
    })

</script>

这将是相同的代码,没有错误:

代码语言:javascript
复制
<script>

    $('#delete-modal').on('show.bs.modal', function(event){

        var button = $(event.relatedTarget)
        var id = button.data('id')
        var location_name = button.data('location_name')
        var modal = $(this);
        modal.find('.modal-body #id').val(id);
        modal.find('.modal-body #location_name').val(location_name);
    })

</script>

您可以在这里找到关于jquery .class选择器的更多信息:https://api.jquery.com/class-selector/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66494949

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档