[英]preventDefault not being recognized in Laravel Mix and Laravel Collective
我试图阻止使用Laravel Collective制作的表单。 有趣的是,它只能工作一次,然后停止工作。 我正在与Laravel Mix一起工作。
这是我的代码:
// Here's the form in my blade
{!! Form::open(['class' => 'confirm-delete','method' => 'DELETE', 'route' => ['users.destroy', $user->id], 'data-title' => __('Delete User') ]) !!}
<button type="submit" class="dropdown-item" href="#" style="cursor: pointer"><i class="fas fa-trash-alt"></i> {{ __('Delete') }}</button>
{!! Form::close() !!}
//这是我的js代码
$(".confirm-delete").submit(function (e) {
alert("It doesn't alert this D:");
var form = this;
e.preventDefault();
swal({
title: form.data("title"),
icon: "warning",
buttons: [
'No, cancel it!',
'Yes, I am sure!'
],
dangerMode: true,
}).then(function (isConfirm) {
if (isConfirm) {
form.submit();
}
});
});
我尝试了这些链接,但没有一个起作用:
https://stackoverflow.com/a/54062772/3675186
我正在使用Laravel 5.6。
终于明白了。 问题是我如何获取数据属性。
这是正确的代码:
$(".confirm-delete").on('submit', function (e) {
var form = this;
e.preventDefault();
swal({
title: $(this).attr("data-title"),
text: "You will not be able to recover this imaginary file!",
icon: "warning",
buttons: [
'No, cancel it!',
'Yes, I am sure!'
],
dangerMode: true,
}).then(function (isConfirm) {
if (isConfirm) {
form.submit();
}
});
});
希望它可以帮助某人:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.