gpt4 book ai didi

javascript - 同时删除多条记录时,如何创建具有多个 ID 号的警报?

转载 作者:行者123 更新时间:2023-11-30 00:58:26 26 4
gpt4 key购买 nike

我有一个记录表,其中每一行都有一个删除链接。单击删除链接时,会显示一条弹出确认消息,其中包含消息和记录 ID。我还在每一行都有一个复选框,可以选中多个复选框,然后单击一个按钮来同时删除这些多条记录。

我想要做的是制作另一条弹出确认消息(用于删除多个作业按钮),但包含将要删除的所有记录 ID。这可能吗?

每行的删除链接如下所示:

<a href="delete-job.php?id=' . $row['id'] . '" onclick="javascript: return confirm(\'Are you SURE you want to delete job ' . $row['id'] . '?\');">Delete</a>

包裹表格的表单如下所示:

<form name="viewjobsanddelete" method="post" action="delete-jobs.php"></form>

每行的复选框如下所示:

<input type="checkbox" name="checkbox[]" id="checkbox[]" value="' . $row['id'] . '" />

删除按钮如下所示:

<input name="delete" type="submit" id="delete" class="btn" value="Delete Multiple Jobs">

delete-job.php(用于删除单个记录/行)有:

 // check if the 'id' variable is set in URL, and check that it is valid
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
// get id value
$id = $_GET['id'];

// delete the entry
$result = mysql_query("DELETE FROM jobs WHERE id=$id") or die(mysql_error());

// redirect back to the view page
header("Location: view-jobs.php");
}
else
// if id isn't set, or isn't valid, redirect back to view page
{
header("Location: view-jobs.php");
}

delete-jobs.php(用于删除多个记录/行)有:

if(isset($_POST['delete'])) {
$checkbox = $_POST['checkbox'];
for($i=0;$i<count($_POST['checkbox']);$i++) {
$del_id = $checkbox[$i];
$sql = "DELETE FROM jobs WHERE id='$del_id'";
//print $sql;
$result = mysql_query($sql);
}
}
echo "<meta http-equiv=\"refresh\" content=\"0;URL=view-jobs.php\">";

那么我应该在哪里修改或添加什么来创建包含要删除的记录/行的多个 ID 号的确认对话框窗口?

最佳答案

这是我的处理方式。

我向每个复选框添加了 class="chk",然后我使用了以下 jquery...

<script>
$(document).ready(function () { //if the page has been fully loaded
/* Get the checkbox values based on the class attached to each check box */

$("#viewjobsanddelete").submit(function(e){ //on submission of form

/* declare a checkbox array */
var chkArray = [];

/* look for all checkboxes that have a class 'chk' attached to it and check if it was checked */
$(".chk:checked").each(function() {
chkArray.push($(this).val());
});

/* we join the array separated by a comma */
var selected;
selected = chkArray.join(',') + ",";

/* check if there are selected checkboxes, by default the length is 1 as it contains one single comma */
if(selected.length > 1){

if (!confirm("You are about to delete these jobs: " + selected)) { //if click cancel instead of ok
e.preventDefault(); //stop form submission
return;
}

}else{
alert("Check one or more checkboxes first.");
e.preventDefault(); //stop form submission
return;
}

});

});
</script>

关于javascript - 同时删除多条记录时,如何创建具有多个 ID 号的警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20360419/

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