Heim > Fragen und Antworten > Hauptteil
最近在研究上拉加载的时候发现有这么一段代码:
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]
删掉再运行,程序正常运行,没有报错。我想知道这种写法有什么好处?