通用的contain函数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通用的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;
}
}
以上是关于通用的contain函数的主要内容,如果未能解决你的问题,请参考以下文章