这里可能需要向上获取父容器来返回:
function getParentInfo(ele) {
let currentElement = ele;
let depth = 0;
while (currentElement && depth < 3) {
if (currentElement.tagName === 'A' || currentElement.tagName === 'IMG') {
return {
href: currentElement.href || currentElement.src,
title: currentElement.title || currentElement.alt,
html: currentElement.outerHTML
};
}
currentElement = currentElement.parentElement;
depth++;
}
return {
href: "",
title: "",
html: ""
};
}