簡體   English   中英

javascript錯誤,回車和換行符

[英]javascript error with carriage return and newline

我在Java中有以下字符串:

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

我用<br/>替換\\r\\n ,如下所示:

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錯誤“未終止的字符串文字”,找不到線索,請幫忙。

聽起來您還沒有從String中得到所有的換行符。

您可能會發現這篇文章很有幫助: 如何用<br />標記替換字符串中的所有換行符?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM