gpt4 book ai didi

带有回车符和换行符的javascript错误

转载 作者:行者123 更新时间:2023-11-29 09:00:49 25 4
gpt4 key购买 nike

我在 Java 中有以下字符串:

"this is text1\r\nthis is text2\r\nthis is text3"

我正在替换 \r\n<br/>如下:

String temp = "this is  text1\r\nthis is text2\r\nthis is text3"
temp = temp.replaceAll("[\r\n]+", "<br/>");

产生以下字符串:"is text1 this is text2 this is text3"

现在,我想将它发送到 JavaScript 元素,如下所示:

var desc_str = "<%=temp%>";
document.getElementById('proc_desc').value = desc_str;

Java 的输出很好,但是在传递到 HTML 元素后,我收到 JavaScript 错误“未终止的字符串文字”,我没有找到线索,请帮忙。

最佳答案

听起来您还没有从字符串中获取所有换行符。

您可能会发现这篇文章有帮助: How do I replace all line breaks in a string with <br /> tags?

关于带有回车符和换行符的javascript错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17602582/

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