function insertText(elemID-6ren">
gpt4 book ai didi

Javascript插入带有换行符的文本

转载 作者:行者123 更新时间:2023-12-01 03:16:53 29 4
gpt4 key购买 nike

我无法让下面的代码工作:

<button type="button" class="btn btn-success btn-sm pull-right" style="margin-bottom:5px;margin-right:1px;" onclick="insertText('replytext', '[quote=<?php echo user::getUsername($message['poster']);?> date=<?php echo $message['post_date'];?>]<?php echo $message['message'];?>[/quote]');">
<i class="fa fa-reply" aria-hidden="true"></i></button>


<textarea class="form-control" rows="5" name="replytext" id="replytext"
style="width:100%;background-color:black;color:white;resize: none;"></textarea>



<script>
function insertText(elemID, replytext)
{
var elem = document.getElementById(elemID);
elem.innerHTML += replytext;
}
</script>

当回复文本包含新行时,它不会像应该那样用该值填充文本区域。有人知道如何解决这个问题吗?它与回复包含/n 或 br 的消息有关。

我测试过。当没有/n 或 br 时,它正在工作。

最佳答案

(代表问题作者发布答案)

str_replace(PHP_EOL, '[br]',($_POST['replytext']))

这完成了工作。 onClick函数不允许 <br />或任何类型的新行。

关于Javascript插入带有换行符的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45500252/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com