我正在为我的 Laravel 应用程序实现 jQueryUI,我想要删除确认,但我未能实现。这是我的代码:
@foreach(array_chunk($items->all(), 3) as $row)
<div class="row" style="margin-bottom:40px;">
@foreach ($row as $item)
<div class="col-md-4">
<img src="{{$item->img_loc}}">
<div>
<strong>Breed: </strong>{{ $item->bname}}<br/>
<strong>GameFarm: </strong>{{ $item->g_origin}}<br/>
<strong>Leg Band: </strong>{{ $item->lband}}
<h3><a href="{{ action('GamefarmsController@edit', $item->id) }}" >Edit</a>|<a id="thelink" href="#">Delete</a></h3>
</div>
</div>
@endforeach
这是我的 jQuery:
<script>
$(function()
{
$( "#dialog-confirm" ).dialog(
{
autoOpen: false,
resizable: false,
height:140,
modal: true,
buttons:
{
"Delete": function()
{
$( this ).dialog( "close" );
},
Cancel: function()
{
$( this ).dialog( "close" );
}
}
});
});
</script>
我想让程序通过这段代码重定向到我的 Controller ,它带有 $items->id ,就像编辑一样在顶部代码中循环。
{{ action('GamefarmsController@delete', $item->id) }}
我尝试对此代码进行实验,但没有任何反应。
编辑:这是剩余的脚本:
<script type="text/javascript">
$(document).ready(function(){
$('#thelink').click(function(){ $('#dialog-confirm').dialog('open'); });
});
</script>
最佳答案
添加一个href
作为删除链接,如下
<a class="confirmLink" href="{{ action('GamefarmsController@delete', $item->id) }}">Delete</a>
然后在js
<script type="text/javascript">
$(document).ready(function() {
$("#dialog-confirm").dialog({
autoOpen: false,
modal: true
});
});
$(".confirmLink").click(function(e) {
e.preventDefault();
var targetUrl = $(this).attr("href"); // get the url of // href="{{ action('GamefarmsController@delete', $item->id) }}"
$("#dialog-confirm").html("Confirm Dialog Box");
$("#dialog-confirm").dialog({
title: "confirmation",
buttons: {
"Delete": function () {
$(this).dialog('close');
window.location.href = targetUrl; // change browser path to url in delete link
},
"Cancel": function () {
$(this).dialog('close');
callback(false);
}
}
});
$("#dialog-confirm").dialog("open");
});
</script>
关于php - Laravel Blade 上的 jQueryUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27498761/