handlebars.js <br>替换掉 内容的换行符

 

JS:

Handlebars.registerHelper('breaklines', function(text) {
    text = Handlebars.Utils.escapeExpression(text);
    text = text.toString();
    text = text.replace(/(\r\n|\n|\r)/gm, '<br>');
    return new Handlebars.SafeString(text);
});

  

HTML template:

<div>
    {{breaklines description}}
</div>

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-30
  • 2021-05-22
  • 2022-12-23
  • 2022-01-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
  • 2022-12-23
  • 2022-01-12
  • 2021-12-05
相关资源
相似解决方案