使用JavaScript字符串的换行符 [英] line breaks using javascript strings

查看:92
本文介绍了使用JavaScript字符串的换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我使用\ n在javascript中换行:-

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

text =这是一个测试" +"\ n" +另一个测试";

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

并使用代码在html中显示它

and to show that in html i m using the code

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

但是我得到的文本没有br

but the text i m getting is without the br

当我在Firebug控制台中签入时,出现换行符(\ n未显示,但创建了换行符)

when checking in firebug console i get is with line break(\n not shown but newline created)

如何使用\ n放置换行符,或者我必须做一些自定义代码而不是\ n

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

谢谢

推荐答案

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

这篇关于使用JavaScript字符串的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆