小程序富文本图片超出过长如何解决?

html 是富文本html代码 

html = html.replace(/<img/gi, '<img class="img_class" ');

标签支持class 所以我们可以用正则给所有的img标签加class类名,也可以给别的标签加。

1
.img_class{
  width: 100% !important;
  height: auto !important;
  display: block !important;
}


function replaceSpecialChar(html) {

    html= content.replace(/&quot;/g,'"');

    html= content.replace(/&amp;/g, '&');

    html= content.replace(/&lt;/g, '<');

    html= content.replace(/&gt;/g, '>');

    html= content.replace(/&nbsp;/g, ' ');

    html= content.replace(/<p/gi, '<p class="p_class" ');

    html = content.replace(/<span/gi, '<span class="span_class" ');

    html= content.replace(/<img/gi, '<img class="img_class" ');

    return html;

}

 


版权声明:本文为qq_32113629原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。