现在的位置: 首页 > 综合 > 正文

两种js获得下一个结点(元素结点)的方法

2012年12月06日 ⁄ 综合 ⁄ 共 264字 ⁄ 字号 评论关闭
function get_nextelem(node){
  var x=node.nextSibling;
  while (x.nodeType!=1)   //通过判断结点属性确认当前结点是否为元素结点,如果是则停止循环返回结点x
   {
      x=x.nextSibling;
   }
  return x;
}
function get_nextelem(node){
   if(node.nodeType==1){
      return node;
   }
   if(node.nextSibling){
      return get_nextelem(node.nextSibling);
   }
   return null;
}

抱歉!评论已关闭.