gpt4 book ai didi

javascript - Laravel 中的 SweetAlert 实现

转载 作者:行者123 更新时间:2023-12-01 05:32:58 24 4
gpt4 key购买 nike

我试图在我的 Laravel 应用程序中发出删除警报,但问题是当我单击删除按钮时,警报出现,但没有确认警报按钮,删除表单被提交,并且该项目被从数据库中删除.

        @foreach($album_names as $album)
<tr>
<td>{{ $album->album_name }}</td>
<td>
{!! Form::open(['url' => "album/{$album->id}", 'method' => 'delete','id'=>'delete_form']) !!}
<button class="btn btn-danger" id="delete">Delete</button>
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<script type="text/javascript">
$('button#delete').on('click', function(){
swal({
title : "Are you sure?",
text : "You will not be able to recover this Album!",
type : "warning",
showCancelButton : true,
confirmButtonColor: "#DD6B55",
confirmButtonText : "Yes, delete it!",
cancelBUttonText : "No, Cancel delete!",
closeOnConfirm : false,
closeOnCancel : false
},
function(isConfirm){
if(isConfirm){
swal("Deleted!","your album has been deleted", "success");
$("#delete_form").submit();
}
else{
swal("cancelled","Your album is safe", "error");
}
}
);});
</script>

最佳答案

您必须指定按钮的类型,因为默认选项是提交表单。不需要js来解决这个问题。只需这样做:

<button type="button">I don't submit anything</button>

<button type="submit">I do submit</button>

关于javascript - Laravel 中的 SweetAlert 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35872265/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com