2011-08-25 44 views
0

当我有以下PHP echo语句转换的javascript:PHP回声

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>

正如你所看到的东西出了问题? 问题是什么?我已经尝试换单" "换单' '

回答

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>'; 
+0

你的例子有同样的错误:http://awesomescreenshot.com/02aj6f761点击没有提示问题,这是目标。 – Iladarsda

+0

@NewUser不,它没有。 http://sandbox.phpcode.eu/g/1be41/2我编辑它。按F5 – genesis

+0

为什么要额外打标?在回声中使用单个'''而不是在echo中使用普通的html更简单? – Iladarsda

2

你必须在onclick声明双单引号,尝试confirm(\'Really delete?\')代替。

0

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

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