찾다

 >  Q&A  >  본문

javascript - iScroll中上拉加载中这段语句是什么意思el.appendChild(li, el.childNodes[0]);?

最近在研究上拉加载的时候发现有这么一段代码:

function pullUpAction () {
    setTimeout(function () {    // <-- Simulate network congestion, remove setTimeout from production!
        var el, li, i;
        el = document.getElementById('thelist');

        for (i=0; i<3; i++) {
            li = document.createElement('li');
            li.innerText = 'Generated row ' + (++generatedCount);
            el.appendChild(li, el.childNodes[0]);
        }
        
        myScroll.refresh();        // Remember to refresh when contents are loaded (ie: on ajax completion)
    }, 2000);    // <-- Simulate network congestion, remove setTimeout from production!
}
el.appendChild(li, el.childNodes[0]);

查文档的时候发现appendChild只带一个参数,于是乎我把el.childNodes[0]删掉再运行,程序正常运行,没有报错。我想知道这种写法有什么好处?

巴扎黑巴扎黑2897일 전298

모든 응답(1)나는 대답할 것이다

  • 高洛峰

    高洛峰2017-04-10 16:51:47

    el.childNodes[0] 是多余的代码,删除即可。

    회신하다
    0
  • 취소회신하다