convert () {
let htmlText = '<img style="border: 0px; width: 537px; display: block;">'
let str = htmlText.replace(/<img[^>]*>/gi, function (match, capture) {
// return match.replace(/(<img[^>]*)(\/?>)/gi, "$1width='100%' $2") // 添加width="100%"
return match.replace(/style\s*?=\s*?([‘"|'])[\s\S]*?\1/ig, 'style="max-width:100%;height:auto;"') // 替换style
})
return str
}
开发日志:调整富文本图片大小
猜你喜欢
转载自blog.csdn.net/qq_37992222/article/details/114390074
今日推荐
周排行