我有一张用Laravel表格包写的表格。
{!! Form::open(['action' => ['Test\\BlogController@destroy', $thread->id], 'method' => 'delete', 'onsubmit' => 'Confirm()' ]) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}现在,我希望Jquery代码以这种形式出现。我希望如果用户单击submit按钮,那么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() !!}但这对我来说并不管用。有什么帮助吗?
发布于 2016-04-12 17:13:31
您可以添加一个类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();
}
});
});希望这能有所帮助。
https://stackoverflow.com/questions/36567645
复制相似问题