js控制标签元素至父容器最顶层

遍历父容器子节点,获取最大z-index值。

function floatToTop(element) {
	const children = element.parentElement.children;
	let max = 0;
    let count = children.length;
    Array.from(children).map((item) => {
        const zIndex = item.style.zIndex === '' ? 0 : parseInt(item.style.zIndex, 0);
        max = Math.max(zIndex, max);
    });
    element.style.zIndex = Math.max(max + 1, count);
}