PHP Echo 函数中的 Javascript 确认框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20899490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 19:34:58  来源:igfitidea点击:

Javascript confirm box inside PHP Echo function

javascriptphpechoconfirm

提问by user3156271

I have a link inside PHP Echo function called "Delete". When user clicks on it, the delete.php page is called and the selected book is deleted from the database. So, I would like to insert a confirmation box asking user if he is sure to delete the book but I don't know how to do it.

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

This is the code:

这是代码:

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

回答by Code L?ver

Use this code:

使用此代码:

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

回答by Vivek S

it works perfectly....

它完美地工作......

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

回答by Anil Meena

you can try this code

你可以试试这个代码

<?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";
?>

回答by Mohammad Faisal Islam

Please try this:

请试试这个:

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

回答by Lee

Please try this way. It's may helps you.

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

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

You can take a look at this demo : http://jsfiddle.net/dq6W6/

你可以看看这个演示:http: //jsfiddle.net/dq6W6/

回答by parker

Try this

试试这个

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