过滤后端返回的html文本标签

let escape2Html=(str)=>{
  var arrEntities = { 'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"' };
  return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function (all, t) { return arrEntities[t]; }).replace(/<img/gi, '<img style="max-width:100%;height:auto;" ');
}

posted @ 2020-03-18 11:06  自律·给我自由  阅读(631)  评论(0编辑  收藏  举报