您好,欢迎访问一九零五行业门户网

FF火狐下获取一个元素同类型的相邻元素实现代码_javascript技巧

复制代码 代码如下:
// 兼容火狐获取一个节点的相同类型的上一个相邻节点
function pervioussiblingsametype(node , cnode )
{
// 为空直接返回null
if(node.previoussibling == null )
{
return null ;
}
else
{
// 节点类型不相等继续递归
if(node.previoussibling.nodetype != cnode.nodetype)
{
return pervioussiblingsametype(node.previoussibling , cnode);
}
// 节点类型相等则返回
else if(cnode.nodetype == node.previoussibling.nodetype)
{
return node.previoussibling ;
}
}
}
// 兼容火狐获取一个节点的相同类型的下一个相邻节点
function nextsiblingsametype(node , cnode)
{
// 为空直接返回null
if(node.nextsibling == null )
{
return null ;
}
else
{
// 节点类型不相等继续递归
if(node.nextsibling.nodetype != cnode.nodetype)
{
return nextsiblingsametype(node.nextsibling , cnode);
}
// 节点类型相等则返回
else if(cnode.nodetype == node.nextsibling.nodetype)
{
return node.nextsibling ;
}
}
}
其它类似信息

推荐信息