我有一个用LaravelForm包编写的Form。
{!! Form::open(['action' => ['Test''BlogController@destroy', $thread->id], 'method' => 'delete', 'onsubmit' => 'Confirm()' ]) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
现在我想要这个表单中的Jquery代码。我希望如果用户点击提交按钮,那么Jquery确认框应该弹出。
这是我的Jquery:
bootbox.confirm("Are you sure?", function(result) {
Example.show("Confirm result: "+result);
});
我就是这么试的:
<script type="text/javascript">
function Confirm()
{
bootbox.confirm("Are you sure?", function(result) {
Example.show("Confirm result: "+result);
});
}
</script>
{!! Form::open(['action' => ['Blog''BlogController@destroy', $thread->id], 'method' => 'delete', 'onsubmit' => 'Confirm()' ]) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
但这对我不起作用。有什么帮助吗?
您可以添加一个类blog-form
,例如:
{!! Form::open(['action' => ['Blog''BlogController@destroy', $thread->id], 'method' =>
'delete', 'class' => 'blog-form' ]) !!}
然后,在使用内联事件onsubmit
时,将js代码中的submit
事件附加到添加的类blog-form
,并在得到肯定响应时提交表单:
$('.blog-form').submit(function(e) {
e.preventDefault();
var blog_form = $(this);
bootbox.confirm("Are you sure?", function(result) {
if (result) {
blog_form.submit();
}
});
});
希望这能有所帮助。