在使用标签内使用字体时,单击事件不起作用
我有一个标签,里面有很棒的字体。有时,当我使用 font Awesome 图标时,它不起作用,需要尝试 3 或 4 次才能起作用。我应该怎么办?
$(".confirm-delete").click(function(e) {
e.preventDefault();
let id = e.target.dataset.id;
Swal.fire({
title: 'Perhatian!',
text: "Apakah Anda yakin untuk menghapus pengisi jabatan ini?",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Ya, hapus',
cancelButtonText: 'Tidak'
}).then((result) => {
if (result.isConfirmed) {
$(`#delete${id}`).submit();
}
})
});
<a href="#" data-id="{{ $servant->id }}" class="btn btn-danger btn-sm confirm-delete">
<form action="{{ route('position.delete', ['congregationId' => $servant->id]) }}" method="post" class="d-inline" id="delete{{ $servant->id }}">
@csrf
@method('delete')
</form>
<i class="fas fa-trash"></i>
</a>
I have A tag which have font awesome inside it. Sometimes it doesnt work when I use the font awesome icon, and need to try this until 3 or 4 times to make it works. What should I do?
$(".confirm-delete").click(function(e) {
e.preventDefault();
let id = e.target.dataset.id;
Swal.fire({
title: 'Perhatian!',
text: "Apakah Anda yakin untuk menghapus pengisi jabatan ini?",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Ya, hapus',
cancelButtonText: 'Tidak'
}).then((result) => {
if (result.isConfirmed) {
$(`#delete${id}`).submit();
}
})
});
<a href="#" data-id="{{ $servant->id }}" class="btn btn-danger btn-sm confirm-delete">
<form action="{{ route('position.delete', ['congregationId' => $servant->id]) }}" method="post" class="d-inline" id="delete{{ $servant->id }}">
@csrf
@method('delete')
</form>
<i class="fas fa-trash"></i>
</a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
容器元素的方式
您需要解决jQuery中的
使用$(this) ,但我不喜欢链接中的表格
在普通JS中,使用CurrentTarget来获取EventHandler分配给的元素
You need to address your way to the container element
In jQuery use $(this)
but I do not like the form inside your link
In plain JS use currentTarget to get the element the eventhandler is assigned to
您可以使用CurrentTarget被束缚。
You can use currentTarget to get the element the event was bound to.
我不喜欢锚点内有一个表单的方式 - 如果您在表单内呈现输入,那么您的 html 将无效,并且可能会导致浏览器呈现它的方式出现一些问题
而不是有一个绑定的锚点您的事件,为什么不在表单中使用按钮,如果结果未确认,则阻止默认操作:
更改 html:
如果结果未确认,则阻止按钮的默认操作:
通过这样做也更容易访问,因为您的表格将起作用(无需确认)即使 JavaScript 被禁用
I don't like the way you have a form inside your anchor - if you have inputs being rendered inside the form, then your html will be invalid and can cause some issues with how the browser renders it
Instead of having an anchor that you tie your event to, why not just use a button inside your form and if the result is not confirmed, prevent the default action:
Change html:
And prevent the default action of the button if the result is not confirmed:
By doing it this way it is more accessible too as your form will work (without the confirmation) even if javascript is disabled