添加确认弹出窗口

时间:2013-04-13 19:52:37

标签: javascript

我有这个代码:

$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?')"

3 个答案:

答案 0 :(得分:0)

您无需将返回添加到onclick,只需

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

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

答案 1 :(得分: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>';?>

答案 2 :(得分:0)

为什么不使用href

<?php
$link = "fruit_list.php?do=delete&id={$fruitdata['id']}";
echo "<a href='{$link}' onclick='return confirm(\"Delete ?\");'>Delete</a>";