gpt4 book ai didi

javascript - PHP回显问题

转载 作者:行者123 更新时间:2023-11-30 09:50:21 24 4
gpt4 key购买 nike

我有一个功能,我的 echo 是:

echo '<tr>
<td align="center" style="padding:5px;"><img src="/chat/emotes/smile.png" onclick="insertSmiley("hallo")"> <br>:illuminati:</td>
</tr>'

问题是 onclick="insertSmiley("hallo")" 必须与 ' 而不是 "。如果我把这在 html 中一切正常,但在我单击时在 php echo 中没有任何反应。

我的 index.php 正文中有这个脚本:

<script type="text/javascript"> 
function insertSmiley(smiley)
{

var currentText = document.getElementById("send");

var smileyWithPadding = " " + smiley + " ";
currentText.value += smileyWithPadding;
currentText.focus();

}
</script>

其他代码在我的 chat.php 中:

    echo '<textarea id="send" maxlength="125" rows="2" placeholder="Enter your message"></textarea>
<tr>
<td align="center" style="padding:5px;"><img src="/chat/emotes/smile.png" onclick="insertSmiley("hallo")"> <br>:illuminati:</td>
</tr>

我真的认为问题是因为我不能在 echo 中使用 '' 而我需要它用于 onClick...('hallo')

最佳答案

使用 \' 只打印 '

反斜杠在 PHP 中用于转义引号内的特殊字符。由于PHP不区分字符串和字符

如果你这样写

echo 'check it \' out'; 

它会给出这样的输出

check it ' out

所以这样使用

echo '<tr>
<td align="center" style="padding:5px;"><img src="/chat/emotes/smile.png" onclick="insertSmiley(\'hallo\')"> <br>:illuminati:</td>
</tr>'

关于javascript - PHP回显问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36895367/

24 4 0