我在PHP Echo函数中有一个名为“Delete”的链接。当用户单击它时,将调用delete.php页面并从数据库中删除所选书籍。所以,我想插入一个确认框,询问用户是否确定要删除该书,但我不知道该怎么做。
这是代码:
echo "<td><a class = 'echo_link' href='delete-book.php?ID={$Book->ID}'> Delete </a></td> \n";
答案 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)
答案 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";