通用的contain函数

用来检测节点所属关系:document.documentElement.contains(document.body)

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;
}
}

posted on 2016-01-28 14:44  迷茫小飞侠  阅读(796)  评论(0编辑  收藏  举报

导航