美文网首页
替换文本换行符和空白符为HTML格式显示

替换文本换行符和空白符为HTML格式显示

作者: Armin0202 | 来源:发表于2017-11-24 12:24 被阅读81次

    场景

    • 后台返回的文本换行符空白符,无法在前端直接展示出来。
    • 需要替换为<br/>&nbsp;,并以HTML格式展示

    const beforetext = ''
    const aftertext = beforetext .replace(/\r|\n|↵/g, '<br/>').replace(/\s/g, '&nbsp;')
    

    相关文章

      网友评论

          本文标题:替换文本换行符和空白符为HTML格式显示

          本文链接:https://www.haomeiwen.com/subject/uawxbxtx.html