肯定节点直接的关系,一般使用contains,可是它只能获得两个节点是否为父子节点不能肯定其余关系。node
function contains(refNode, otherNode){ if(typeof refNode.contains == 'function' && (!client.engine.webkit || client.engine.webkit >= 522)){ return refNode.contains(otherNode) } else if(typeof refNode.compareDocumentPosition == "function"){ return !!(refNode.compareDocumentPosition(otherNode) & 16) } else{ var node = otherNode.parentNode; do{ if(node === refNode){ return true } else { node = node.parentNode } } while (node !== null); return false; } }