在字符串中使用新行(\\\<br/>)并在HTML中呈现相同的内容 [英] Using new line(\n) in string and rendering the same in HTML
本文介绍了在字符串中使用新行(\\\<br/>)并在HTML中呈现相同的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串说
I have a string say
string display_txt = "1st line text" +"\n" + "2nd line text";
在Jquery中,我正在尝试使用
in Jquery, I am trying to use
('#somediv').html(display_txt).css("color", "green")
很明显,我期待我的消息被显示在两行中,但是\\\
正在消息中显示。任何快速修复?
quite clearly I am expecting my msg to be displayed in 2 lines, but instead \n is being displayed in the message. Any quick fixes for that?
谢谢,
推荐答案
code $< br /> 用于html中的新行:
Use <br />
for new line in html:
display_txt = display_txt.replace(/\n/g, "<br />");
这篇关于在字符串中使用新行(\\\<br/>)并在HTML中呈现相同的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文