首页 > 其他 > 详细

Node.prototype.contains

时间:2017-01-03 18:34:54      阅读:92      评论:0      收藏:0      [点我收藏+]
document.documentElement.contains(document.body) // true
document.documentElement.compareDocumentPosition(document.body) // 20
//safari5+是把contains方法放在Element.prototype上而不是Node.prototype
if (!DOC.contains) {
    Node.prototype.contains = function (arg) {
        return !!(this.compareDocumentPosition(arg) & 16)
    }
}
avalon.contains = function(root, el) {
    try {
        while ((el = el.parentNode))
            if (el === root)
                return true
        return false
    } catch (e) {
        return false
    }
}

 

 

 

技术分享

Node.prototype.contains

原文:http://www.cnblogs.com/jzm17173/p/6245557.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!