`
zhangyaochun
  • 浏览: 2564079 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

hasParent的设计

阅读更多

 

   场景

 

        判断指定的元素是否还有指定的父元素

 

   代码设计:

 

/**
 *@name hasParent
 *@param {HTMLElement} node
 *@param {HTMLElement} parent
 *@return {Boolean}
/
function hasParent(node,parent){
        
        while(node){
              if(node == parent){
                     return true;
              }
 
              node = node.parentNode;
        }

        return false;
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics