//多张图片也可以支持
function imageUrlHander(content){
content = `<p><img src="../search/albumsdetail?tn=albumsdetail&word=%E5%9F%8E%E5%B8%82%E5%BB%BA%E7%AD%91%E6%91%84%E5%BD%B1%E4%B8%93%E9%A2%98&fr=searchindex_album%20&album_tab=%E5%BB%BA%E7%AD%91&album_id=7&rn=30'" title="1591061098200080612.jpg"/></p>`; //富文本内容(后台返回图片路径不正确)
var reg = /<img [^>]*src=['"]([^'"]+)[^>]*>/g; //img 标签取src里面内容的正则
var srcArr = content.match(reg);//取到所有img标签放到数组中
if(srcArr.length){
for (let i = 0; i < srcArr.length; i++) {
var srcImg = srcArr[i].replace(reg, '$1');
var url = srcImg.slice(2);
var newImg = srcArr[i].replace(srcImg, 'https://image.baidu.com' + url);
content = content.replace(srcArr[i],newImg);
}
}
console.log(content)
//`<p><img src="https://image.baidu.com/search/albumsdetail?tn=albumsdetail&word=%E5%9F%8E%E5%B8%82%E5%BB%BA%E7%AD%91%E6%91%84%E5%BD%B1%E4%B8%93%E9%A2%98&fr=searchindex_album%20&album_tab=%E5%BB%BA%E7%AD%91&album_id=7&rn=30'" title="1591061098200080612.jpg"/></p>`
return content;
}
01-19
06-09
1293
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-17
1293
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-25
179
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)