作者:Remember_Mi | 来源:互联网 | 2023-10-13 17:21
12345678910111213141516function buildFragment(elems, context) { var fragment = context.createDocu
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| function buildFragment(elems, context) {
var fragment = context.createDocumentFragment(),
nodes = [],
i = 0,
elem,
l = elems.length;
for (; i elem = elems[i];
//创一个元素div做为容器
tmp = fragment.appendChild(context.createElement("div"));
//放到文档碎片中
tmp.innerHTML = elem;
}
return fragment;
} |
创建文档片段的时候不都是用document.createDocumentFragment()吗?
这里用个context参数是什么意思?