📜  文档片段 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:09.435000             🧑  作者: Mango

代码示例1
var list = document.querySelector('#list')
var fruits = ['Apple', 'Orange', 'Banana', 'Melon']

var fragment = new DocumentFragment()

fruits.forEach(function (fruit) {
  var li = document.createElement('li')
  li.innerHTML = fruit
  fragment.appendChild(li)
})

list.appendChild(fragment)