一、字符串——正则表达式
let allImage = [];
let str = "<p>这是个字符串<img src='http://www.baidu.com' /></p>";
str.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function (match, capture) {
allImage.push(capture);
});
console.log(alllImage);
二、div——dom节点
//vue template
<div ref="img">
<p>这是个字符串<img src="http://www.baidu.com" /></p>
</div>
//javascript
let allImage = [];
let imgDiv = this.$refs.img.getElementsByTagName("img");
imgDiv.forEach(i => {
allImage.push(i.src)
});
console.log(allImage);