【发布时间】:2022-02-01 02:09:10
【问题描述】:
我有一个表,我在每一行上使用 data-href 属性,这样我就可以访问每一行对应的页面。在每一行的末尾,我放置了一个“编辑”和一个“删除”按钮。他们工作正常,直到我添加了甜蜜警报 2 确认模式。问题是当我单击删除按钮时,父 tr 节点的 data-href 被触发(以及删除功能)。如何从 tr data-href 功能中排除此按钮(甚至整个删除表单)?
tr 节点:
<tr data-href="view_client/{{ $client->id}}">
<td><strong>{{$client->surname }}</strong></td>
...
<td style="width:15%" >
<div class="d-flex justify-content-evenly">
<a href="/edit_client/{{ $client->id }}" class="btn btn-sm btn-warning flex-fill">
<i class="far fa-edit"></i>Edit</a>
<form action="/clients/{{ $client->id }}" id="deleteForm" method="POST">
@method('DELETE')
@csrf
<button type="button" class="btn btn-danger show_confirm"><i class="far fa-trash-alt"></i></button>
</form>
</div>
</td>
</tr>
show_confirm的js:
$('.show_confirm').on('click', function(e) {
var form = $('#deleteForm');
e.preventDefault();
Swal.fire({
title: "Delete Confirmation",
text: "Are you sure?",
icon: "warning",
showCancelButton: true,
confirmButtonColor: '#ff0f15',
cancelButtonColor: '#ed032d9e9e9e',
confirmButtonText: 'Yeah! Go ahead!'
})
.then((willDelete) => {
if (willDelete.isConfirmed) {
form.trigger('submit');
}
});
});
【问题讨论】:
-
@ArleighHix 谢谢!那成功了!只需复制我的代码并添加 e.stopPropagation();以便我能最好地接受答案。
标签: html href bootstrap-5