我在Laravel(PHP框架)中编写了一个公式器,这个公式器获取了一些数据并将它们与路由一起发送到我的控制器。我的控制器具有从数据库中删除数据的功能。好吧,现在我想要一个javascript/Bootstrap复选框,并找到了这个:
<script>
bootbox.confirm("Are you sure?", function(result) {
Example.show("Confirm result: "+result);
});
</script>
这里有这个代码的寿命测试:http://bootboxjs.com
现在我想将此代码与我的 laravel 公式器连接起来。有人可以帮我吗?我真的不太用javascript。
谢谢!
配方:
{!! Former::horizontal_open()->method('DELETE')->action(action("Test''TestController@destroy", $thread->id)) !!}
{!! Former::large_danger_submit('Delete') !!}
{!! Former::close() !!}
当前代码:
{!! Former::horizontal_open()->method('DELETE')->action(action("Test''TestController@destroy", $thread->id))->id('conf') !!}
{!! Former::large_danger_submit('Delete') !!}
<script>
$('.conf').submit(function(event) {
event.preventDefault();
var subm = confirm("Are you sure?");
if(subm){
$('.conf p').text('Pressed Ok');
this.submit();
}else{
$('.conf p').text('Pressed Cancel');
return false;
}
});
</script>
{!! Former::close() !!}
获取 j.query、JavaScript 和 bootstrap,如下所示:
整个大师刀片.php:
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
</head>
<body>
@include("elements.navbar")
<div class="container">
<hr />
@yield('content')
<hr />
</div>
@yield('custom-script')
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</body>
</html>
带有表单的 HTML 和 JS 确认代码当然会获取 master.blade.php 的数据。因此支持查询和JS/Bootstrap。
**Jquery required.**
另一种没有引导箱的方式
<html>
<head>
//head
</head>
<body>
@include("elements.navbar")
<div class="container">
<hr />
@yield('content')
<hr />
</div>
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
@yield('custom-script')
</body>
</html>
您的表单视图
{!! Former::horizontal_open()->method('DELETE')->action(action("Test''TestController@destroy", $thread->id))->id('conf') !!}
{!! Former::large_danger_submit('Delete') !!}
{!! Former::close() !!}
@section('custom-script')
<script>
//DOM Ready
$(function(){
$('#conf').submit(function(event) {//form ID (not Class as you have ->id('conf'))
event.preventDefault();
var subm = confirm("Are you sure?");
if(subm){
console.log('Press Ok')
this.submit();
}else{
console.log('Press Cancel')
return false;
}
});
});
</script>
@stop
工作小提琴