开发者

line breaks using javascript strings

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜