js 元素遍历

 2018-06-26

//百度首页测试
var i,
    len = 0,
    element = document.querySelector('#s_form_wrapper'),
    child = element.firstElementChild;

while(len<element.childElementCount){
    console.log(child,'111')
    child = child.nextElementSibling;
    len++;
}

 

 

javascript高级程序设计中的 遍历方法不能处理最后一个子节点,具体代码如下:

var i,
    element = document.querySelector('#s_form_wrapper'),
    child = element.firstElementChild;

while(child!=element.lastElementChild){
    console.log(child,'111')
    child = child.nextElementSibling;
}

 

 

posted @ 2018-06-26 11:55  淡然_  阅读(220)  评论(0编辑  收藏  举报