JS 使用for循环遍历子节点查找元素

时间:2014-09-06    点击:104   

这篇文章主要介绍了JS 使用for循环配合数组遍历子节点查找元素

function nextChildNode(node,clazz,tagName){ 
var count= node.childElementCount; 
for(var i=0;i<count;i++){ 
if(node==undefined || node.children[i]==undefined){ 
continue; 
} 
if(clazz){ 
if(node.children[i].getAttribute('class')==clazz){ 
return node.children[i]; 
} 
}else{ 
if(node.children[i].tagName==tagName){ 
return node.children[i]; 
} 
} 


} 
return null; 
} 

function getChildNode(node,classArg,tagNodeArg){ 
for(var i=0;i<classArg.length;i++){ 
node=nextChildNode(node,classArg[i]); 
} 
for(var i=0;i<tagNodeArg.length;i++){ 
node=nextChildNode(node,null,tagNodeArg[i]); 
} 
return node; 
} 

function getItemId(node){ 
var classNode=['itemInfo','itemDesc'],tagNode=['P','BUTTON']; 
node=getChildNode(node,classNode,tagNode); 
alert(node.getAttribute('itemid')); 

} 

#调用函数 
getItemId($(".shopItem")[0]); 
js和jquery中循环的退出和继续学习记录
jquery实现html页面 div 假分页有原理有代码
JavaScript及jquey实现多个数组的合并操作
jquery用offset()方法获得元素的xy坐标
jquery向上向下取整适合分页查询
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved