开发者

PHP convert javascript when echo

开发者 https://www.devze.com 2023-03-31 04:25 出处:网络
I have following PHP echo statement: echo \"<td><a href=\'delete-news.php?deleteID=\".$id.\" onclick=\'return confirm(\'Really delete?\');\'>Delete</a></td>\";

I have following PHP echo statement:

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

which is convert to html as:

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

As you can see something has gone wrong? What is the problem? I ha开发者_JAVA技巧ve already tried swaping " " for single ' '.


Your have double single quotes in the onclick statement, try confirm(\'Really delete?\') instead.


You have forgot ' after href. Use it like

Double quotes:

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

Single quotes:

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


You have href not closed. Also, your 'Really delete' cause trouble too. Try this

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

精彩评论

暂无评论...
验证码 换一张
取 消