Can I escape html special chars in javascript?

后端 未结 15 1452
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 02:26

I want to display a text to HTML by a javascript function. How can I escape html special chars in JS? Is there an API ?

15条回答
  •  遥遥无期
    2020-11-22 03:01

    If you already use modules in your app, you can use escape-html module.

    import escapeHtml from 'escape-html';
    const unsafeString = '';
    const safeString = escapeHtml(unsafeString);
    

提交回复
热议问题