请帮忙......我正在为消息系统编写一个 php 脚本。注释通过函数使用 $comments 在 php 中显示。我试图在 javascript 中使用灯箱,以便用户可以选择删除每条评论。如何将以下 php 脚本与 javascript 代码结合起来:
<?php
$comments .= " <font size='3'> ?>
<a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">**Delete**</a>
<div id="light" class="white_content">
<form action="<?php=$_SERVER['PHP_SELF'];?>" method="post">
<input type="submit" name="submit_1" value="Delete Photo" >
</form>
<a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'"><button> Cancel </button></a></div>
<div id="fade" class="black_overlay"></div>
<?php $comments .= "</font>"; ?>
最佳答案
<?php
$comments .= <<<EOD
<font size='3'>
<a href="javascript:void(0)" onclick="document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">**Delete**</a>
<div id="light" class="white_content">
<form action="$_SERVER[PHP_SELF]" method="post">
<input type="submit" name="submit_1" value="Delete Photo" >
</form>
<a href="javascript:void(0)" onclick="document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'"><button> Cancel </button></a>
</div>
<div id="fade" class="black_overlay"></div>
</font>
EOD;
?>
类似的东西应该有效。请记住“EOD;”需要单独存在,位于一行的开头。
另请参阅http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
您试图错误地使用“?> html...”结构。它不会“返回”字符串,而是直接打印出来 - 每当解析器通过它时,它就会发送到浏览器,而不是添加到 $comments
关于javascript - 正确结合 javascript 和 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20525783/