简体   繁体   English

如何使用PHP在链接中包含Javascript删除确认?

[英]How To Include Javascript Delete Confirm in a Link Using PHP?

This block of code builds a whole table with data in rows and 2 columns, Edit, and Delete. 此代码块使用行和2列(编辑和删除)中的数据构建整个表。 I figure someone might want that code besides me getting question answered. 我认为除了我得到问题的答案之外,可能还会有人想要该代码。 (by the way the implode function is taking 13 columns in my recordset and displaying them. Pretty concise.) (顺便说一下,爆破功能在我的记录集中占据了13列并显示它们。非常简洁。)

 $result = mysqli_query($conn, $sql); 


$tablebuild = "<table border = '1' >";
$tablebuild .="<tr><td>Edit</td><td>Delete</td>";
while ($property = mysqli_fetch_field($result)) {
   $tablebuild .= "<td>".$property->name."</td>";
}

$tablebuild .="</tr>";

while ($row = mysqli_fetch_row($result)) // Data
{ $tablebuild .= '<tr><td><a href="leader_edit.php?MemberID='.$row[0].'" onClick=\"return confirm("You sure?");\" >Edit</a></td><td><a href="leaders.php?delete=yes&MemberID='.$row[0].'">Delete</a></td><td align="center">'.implode($row,'</td><td align="center">')."</td></tr>\n"; }


$tablebuild .= "</table>";

echo $tablebuild;

?>

I put my onClick event in the link that calls Edit page for that MemberID because I didn't want to keep deleting Members while onClick wasn't working. 我将onClick事件放在调用该MemberID的“编辑”页面的链接中,因为我不想在onClick无法正常工作时继续删除Member。 After getting it to work I would then move it to nearly identical scripted link that calls delete function. 在使其正常工作之后,我将其移至调用delete函数的几乎相同的脚本链接。

onClick=\\"return confirm("You sure?");\\" onClick = \\“返回确认(”您确定吗?“); \\”

However, it doesn't seem to be working. 但是,它似乎不起作用。 I've tried all sorts of escape and quotes but no luck. 我尝试了各种转义和引号,但没有运气。 Maybe it isn't possible in a link. 也许在链接中是不可能的。 I think the code is a good concise way to display a recordset in Html table format and would be good to save in one's library of code. 我认为该代码是一种以Html表格式显示记录集的好方法,并且可以很好地保存在代码库中。

Perhaps placing the message 'You sure?' 也许将消息“您确定?” in single quotes and escaping those will work for you: 用单引号引起来并转义它们将为您工作:

onClick="return confirm(\'You sure?\')"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM