所以我想使用 sweetalert2 重定向到,例如使用 ?ID= 的內容刪除.php。我該如何放入東西?這是我的代碼。第一個是在 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,如果可能的話,我希望它可以重定向到deleting.php?ID=4。謝謝你!是否可以從 GET 信息激活 sweetalert2?如何激活?
1 回答

牧羊人nacy
TA貢獻1862條經驗 獲得超7個贊
除了 PHP 之外,JavaScript 中的字符串連接不是用點來完成的。您必須使用+字符來連接。因此,您的代碼必須類似于以下示例;
window.location = "deleting.php?ID=" + id;
可以通過 GET 參數將 SweetAlert 作為 JavaScript 庫激活。只需使用URLSearchParams本機對象即可。
const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('myParam');
if (myParam) {
// initialize here
}
- 1 回答
- 0 關注
- 168 瀏覽
添加回答
舉報
0/150
提交
取消