如何将\ n转换为HTML换行符 [英] How to convert \n to HTML line break

查看:857
本文介绍了如何将\ n转换为HTML换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此插件来解析bbcode bbcodeparser

I am using this plugin to parse bbcode bbcodeparser

但它无法将 \ n 转换为< br />

我尝试添加这个:

replace(/\r?\n|\r/g, '<br>')

...但是它不起作用。

...but it didn't work.

如何实现换行功能?

推荐答案

如果你这样做是为了在html中显示新行和返回运输,那么你不需要明确地这样做。你可以通过设置 white-space 属性 pre-line 值在css中完成。

If you are doing this to show new line and return carriage in html, then you don't need to do it explicitly. You can do it in css by setting the white-space attribute pre-line value.

<span style="white-space: pre-line">@Model.CommentText</span>

这篇关于如何将\ n转换为HTML换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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