doudi2833 2015-11-14 05:46
浏览 66
已采纳

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

This block of code builds a whole table with data in rows and 2 columns, Edit, and Delete. 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.)

 $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>
"; }


$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. After getting it to work I would then move it to nearly identical scripted link that calls delete function.

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

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.

  • 写回答

1条回答 默认 最新

  • douyanning3724 2015-11-14 14:33
    关注

    Perhaps placing the message 'You sure?' in single quotes and escaping those will work for you:

    onClick="return confirm(\'You sure?\')"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动