let textareaHtml = response.detail; // 循环,分别取出每个item的富文本内容
let img = textareaHtml.match(/<img[^>]+>/g); // 利用正则,取出所有img标签,数据格式为数组
console.log(img, "textareaHtml");
let arrImg = ""; // 定义空字符串,下面会往里边填充img标签
for (let j = 0; j < img.length; j++)
{
// 正则匹配,摘出img标签下的src里的内容,即capture
img[j].replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function(match, capture)
{
// arrImg += '<div class="img-box" style="background: url(\'' + capture + '\') no-repeat center / cover;width:30.3333%;height:100px;float:left;margin: 0 1.5% 10px 1.5%;" ></div>';
arrImg += capture + ","; //这快就可以拼接想要的dom
});
// 这边为了不让九宫格里的图片压缩,所以放置在div的背景里
}
//这快加了一个截取最后一个逗号的操作
let newImg = (arrImg.substring(arrImg.length - 1) === ",") ? arrImg.substring(0, arrImg.length - 1) : arrImg; // 将取出来的img放置到newImg中
this.topicList = newImg.split(",");
富文本里摘出每个img标签内容
最新推荐文章于 2023-02-22 15:53:27 发布