0

我有这个代码:

$action = "window.location = 'fruit_list.php.php?do=delete&id={$fruitdata['id']}";
echo '<a style="cursor: pointer" onclick="javascript:' . $action . '">Delete</a>';?>

有没有办法添加以下代码以在单击链接时弹出确认框?

 onclick="return confirm('are you sure?')"
4

3 回答 3

0

您不需要在 onclick 中添加返回,只需

<a href='#' onclick='confirm("Are you sure?")'> Click </a>

http://jsfiddle.net/PFKFq/1/

于 2013-04-13T22:47:24.827 回答
0
$action = "if(window.event) event=window.event; event.preventDefault();if (confirm('Are you sure?')){window.location = 'fruit_list.php.php?do=delete&id={$fruitdata['id']} }";
echo '<a style="cursor: pointer" onclick="javascript:' . $action . '">Delete</a>';?>
于 2013-04-14T02:59:15.233 回答
0

为什么你不使用href

<?php
$link = "fruit_list.php?do=delete&id={$fruitdata['id']}";
echo "<a href='{$link}' onclick='return confirm(\"Delete ?\");'>Delete</a>";
于 2013-04-14T07:07:20.313 回答