我正在为我的移动应用项目使用backbone.js。我的问题是如何在段落中添加“br”?这是我的代码。
<p><%= product.get('description') %></p>
数据库中的数据
The COOLPIX S620 combines beauty and brains.
It features the worlds fastest start up in just 0.7 seconds.
我想要的就是这样
The COOLPIX S620 combines beauty and brains.
It features the worlds fastest start up in just 0.7 seconds.
不是这个
The COOLPIX S620 combines beauty and brains. It features the worlds fastest start up in just 0.7 seconds.
最佳答案
您可以在 JavaScript 中使用正则表达式在每个句子后添加换行符。
后跟大写字母的句点的搜索参数为 /\.(?=[A-Z])/g
description.replace(/\.(?=[A-Z])/g, '<br />');
关于Javascript - 如何将 'br' 添加到段落中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21655824/