recherche

Maison  >  Questions et réponses  >  le corps du texte

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 Il y a quelques jours300

répondre à tous(1)je répondrai

  • 高洛峰

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

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

    répondre
    0
  • Annulerrépondre