PHP convert javascript when echo
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>";
精彩评论