我有这个代码:
$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?')"
我有这个代码:
$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?')"
您不需要在 onclick 中添加返回,只需
<a href='#' onclick='confirm("Are you sure?")'> Click </a>
$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>';?>
为什么你不使用href
?
<?php
$link = "fruit_list.php?do=delete&id={$fruitdata['id']}";
echo "<a href='{$link}' onclick='return confirm(\"Delete ?\");'>Delete</a>";