最近需要在前台对编辑器生成的html代码做处理,需要进行编码,考虑到js没有直接对html编码的支持,看了下jQuery的实现,发现真是超级简单呀,顺便记录一下,需要的时候可以参考一下。

function htmlEncode(value){
    if (value) {
        return jQuery('<div />').text(value).html();
    } else {
        return '';
    }
}
 
function htmlDecode(value) {
    if (value) {
        return $('<div />').html(value).text();
    } else {
        return '';
    }
}

相关文章:

  • 2021-11-27
  • 2021-05-19
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
  • 2021-07-19
猜你喜欢
  • 2022-12-23
  • 2021-09-25
  • 2021-12-28
  • 2022-12-23
  • 2021-07-21
  • 2022-12-23
相关资源
相似解决方案