<img src="https://res.cloudinary.com/dvhhqcxre/image/upload/v1611495185/zenith/tldyffcvvfm9fj51pvjp.jpg">
我想去掉img标签,我只想要图像链接
const image = document.querySelector('img')
image.outerHTML = image.src
<img src="https://res.cloudinary.com/dvhhqcxre/image/upload/v1611495185/zenith/tldyffcvvfm9fj51pvjp.jpg">
您可以使用DOMParser
来解析字符串并获得图像的src
属性:
const str = `<img src="https://res.cloudinary.com/dvhhqcxre/image/upload/v1611495185/zenith/tldyffcvvfm9fj51pvjp.jpg">`;
const res = new DOMParser().parseFromString(str, "text/html").querySelector('img').src;
console.log(res)