【发布时间】:2020-07-09 12:16:19
【问题描述】:
所以我想使用 sweetalert2 重定向到,比如删除 .php 和 ?ID= 东西。我怎么把东西放进去?这是我的代码。第一个是在 php echo html 中,这样我就可以从 sql 数据库中放入所有内容。
echo'
<td style="text-align: center;"> <div class="btn-group dropup">
<button class="btn btn-info dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Action
</button>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="edit_form.php?ID='.$operatives['ID'].'">Edit</a>
<a class="dropdown-item red" onclick="oof("'.$operatives['ID'].'")" href="#">Purge</a>
</div>
</div> </td>'
这是 sweetalert2 代码
<script>
function oof(id){
var MyId = id;
Swal.fire({
title: 'Are you sure?',
text: "You will be purging this person's account.",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#d33',
cancelButtonColor: '#3085d6',
confirmButtonText: 'Yes, purge account'
}).then((result) => {
if (result.value) {
window.location = "deleting.php?ID="+MyId;
}
})
}
</script>
假设 ID 为 4,如果可能,我希望它可以重定向到 delete.php?ID=4。谢谢!
也可以从 GET 信息中激活 sweetalert2 吗?如何激活?
【问题讨论】:
-
你的问题不清楚,你到底想要什么?
-
我想将信息从 php 传递给 sweetalert 的函数,以便它可以使用该函数将我重定向到具有 ?id=something 信息的另一个站点
-
在 JavaScript 中连接字符串是通过
+而不是.完成的。所以你的重定向必须看起来像window.location = "deleting.php?ID=" + id;。就是这样。
标签: javascript php html json sweetalert2