四季奶青大杯正常糖:应该稳的, 去年秋招我面过美团成都闪购, 面试官说他们处于业务扩张期, 今年还要招一批人
0 点赞 评论 收藏
分享
效忠不下去辣:<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div>
father
<div id="node1">son1</div>
<div id="node2">son2</div>
</div>
<script>
function findFather(node1, node2) {
const father = [];
let currentNode = node1;
while (currentNode) {
father.push(currentNode);
currentNode = currentNode.parentNode;
}
// console.log('father->',father)
let cur = node2;
while (cur) {
if (father.indexOf(cur) >= 0) {
return cur;
} else {
cur = cur.parentNode;
}
}
return null;
}
let node1 = document.getElementById("node1");
let node2 = document.getElementById("node2");
console.log(findFather(node1, node2));
</script>
</body>
</html>
0 点赞 评论 收藏
分享
关注他的用户也关注了: