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(/"/g,'"');
html= content.replace(/&/g, '&');
html= content.replace(/</g, '<');
html= content.replace(/>/g, '>');
html= content.replace(/ /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;
}