PHP回声时转换javascript

时间:2011-08-25 09:36:57

标签: php javascript

我有以下PHP echo语句:

echo "<td><a href='delete-news.php?deleteID=".$id." onclick='return confirm('Really delete?');'>Delete</a></td>";

将转换为html:

<td class="last-td nth-8"><a delete?');'="" confirm('really="" return="" href="delete-news.php?deleteID=5 onclick=">Delete</a></td>

你可以看到出了什么问题? 问题是什么?我已尝试将" "换成单' '

3 个答案:

答案 0 :(得分:2)

您在onclick声明中有双引号,请尝试confirm(\'Really delete?\')

答案 1 :(得分:1)

你在href之后忘记了'。像

一样使用它

双引号:

echo "<td><a href='delete-news.php?deleteID=".$id."' onclick=\"return confirm('Really delete?');\">Delete</a></td>";

单引号:

echo '<td><a href="delete-news.php?deleteID='.$id.'" onclick="return confirm(\'Really delete?\');">Delete</a></td>';

答案 2 :(得分:0)

href未关闭。此外,您的'Really delete'也会造成麻烦。试试这个

echo "<td><a href='delete-news.php?deleteID=$id' onclick='return confirm(\"Really delete?\");'>Delete</a></td>";