PHP Echo函数中的Javascript确认框

时间:2014-01-03 08:25:47

标签: javascript php echo confirm

我在PHP Echo函数中有一个名为“Delete”的链接。当用户单击它时,将调用delete.php页面并从数据库中删除所选书籍。所以,我想插入一个确认框,询问用户是否确定要删除该书,但我不知道该怎么做。

这是代码:

echo "<td><a class = 'echo_link' href='delete-book.php?ID={$Book->ID}'> Delete </a></td> \n";

6 个答案:

答案 0 :(得分:4)

使用此代码:

echo "<td>
<a class = 'echo_link' href='#' onclick='if(confirm(\"message\")) location.href=\"delete-book.php?ID={$Book->ID}\";'> Delete </a>
</td> \n";

答案 1 :(得分:3)

它完美无缺......

 <a  href='http://www.google.com' onclick="return confirm('Are U sure?');"> Delete </a>

答案 2 :(得分:2)

请试试这个:

echo "<td><a class = 'echo_link' href='delete-book.php?ID=5' onclick='return confirm(\"Are you sure to delete?\")'> Delete </a></td> \n";

答案 3 :(得分:2)

你可以试试这段代码

<?php $bookid =  $Book->ID; ?>
<td>
<a class = 'echo_link' href='<?php echo "delete-book.php?ID=$bookid"; ?>'  onclick='return confirm("Are you sure?");'> Delete </a>
</td> 
<?php echo"\n";
?>

答案 4 :(得分:0)

请尝试这种方式。它可能会帮助你。

onclick="return confirm('Are you sure?');"

您可以查看此演示:http://jsfiddle.net/dq6W6/

答案 5 :(得分:-1)

试试这个

echo "<td><a class = 'echo_link' onclick='return confirm('Are you sure?');' href='delete-book.php?ID={$Book->ID}'> Delete </a></td> \n";