js 正则去除一段html里 img标签里的style,添加图片自适应 max-width:100%
convert () {
let htmlText = '<img style="border: 0px; width: 537px; display: block;">'
let str = htmlText.replace(/<img[^>]*>/gi, function (match, capture) {
return match.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/ig, 'style="max-width:100%;height:auto;"')
})
return str
},