我正在尝试通过删除确认模式获取location_name,但它没有返回任何结果。
删除按钮:
<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>删除模式:
{{-- 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:
<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未显示数据

发布于 2021-03-05 19:00:32
丢失的点(.)有一个错误对于类模式-当您使用modal.find时,对于'JS jQuery‘代码中的两个值。我写这篇评论是为了让你看看它在哪里以及它发生的原因。
<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>这将是相同的代码,没有错误:
<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/。
https://stackoverflow.com/questions/66494949
复制相似问题