首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在javascript字符串中插入新段落?

如何在javascript字符串中插入新段落?
EN

Stack Overflow用户
提问于 2013-11-08 02:02:42
回答 2查看 7.5K关注 0票数 2

我正在使用一个脚本来替换Google模板中的字符串。如果我使用\n命令,我可以在模板中得到一个新行。

代码语言:javascript
复制
sample = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. \n Lorem Ipsum is simply dummy text of the printing and typesetting industry."

我得到了这样的东西:

代码语言:javascript
复制
      Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum is simply dummy text of the printing and typesetting industry.

但是我不想添加一个新字符串,而是添加一个新段落(根据模板设置):

代码语言:javascript
复制
      Lorem Ipsum is simply dummy text of the printing and typesetting industry.
      Lorem Ipsum is simply dummy text of the printing and typesetting industry.

有办法这么做吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-11-08 09:33:14

不能从段落的内容中创建段落,可以在脚本本身中切片字符串,从而在脚本中使用appendParagraph方法。

票数 1
EN

Stack Overflow用户

发布于 2013-11-08 09:39:05

代码语言:javascript
复制
    sample = "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.
 </p><p> Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>"

如果您有想要段落的字符串部分,这将有效。如果没有,则可以在字符串中用/n替换</p><p>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19850320

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档