肯定節點直接的關係,一般使用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; } }