开发者

line breaks using javascript strings

开发者 https://www.devze.com 2023-02-01 22:09 出处:网络
I m breaking a line in javascript using \\n for example: - text = \"this is a test\" + \"\\n\" + \"another test\";

I m breaking a line in javascript using \n for example: -

text = "this is a test" + "\n" + "another test";

and to show that in html i m using the code

text = text.replace('\n' , '<br>');

but the text i m getting is without the br

when check开发者_C百科ing in firebug console i get is with line break(\n not shown but newline created)

how can i place line breaks using \n or i have to do some custom code instead of \n

thanks


var newText = text.replace(/\n/g , "<br>");


use double quotes to not escape the \n

try this:

text = text.replace("\n" , "<br>");


/\r\n|[\r\n]/g <- this is what I use. I am a pessimist..

0

精彩评论

暂无评论...
验证码 换一张
取 消