echo '<a href="url_to_delete" onclick="return confirm('Are you sure want to delete') ;">Delete</a>';
我在单引号上遇到问题。解析错误:语法错误、意外的"Are"(T_STRING)、预期 '","' 或 ';' 我尝试更改
echo '<a href="url_to_delete" onclick="return confirm('.'Are you sure want to delete'.') ;">Delete</a>';
但是弹出的confimation不起作用。我需要在 PHP 中使用单引号,但不需要在双引号上使用。
您需要使用反斜杠转义单引号:
echo '<a href="url_to_delete" onclick="return confirm('Are you sure want to delete') ;">Delete</a>';
你的问题之一是你没有转义字符串中的引号。
echo '<a href="url_to_delete" onclick="return confirm('Are you sure want to delete') ;">Delete</a>';
另一个是你正在回显纯html,你可以退出php模式并简单地输出html
...
?>
<a href="url_to_delete" onclick="return confirm('Are you sure want to delete') ;">Delete</a>
<?php
...