/**
* javascrit原生实现jquery的append()函数
* @param parent
* @param text
*/
function append(parent, text) {
if (typeof text === ‘string’) {
console.log(‘string’);
var temp = document.createElement(‘div’);
temp.innerHTML = text;
// 防止元素太多 进行提速
var frag = document.createDocumentFragment();
while (temp.firstChild) {
frag.appendChild(temp.firstChild);
}
parent.appendChild(frag);
} else {
parent.appendChild(text);
}
}
javascrit原生实现jquery的append()函数
最新推荐文章于 2024-09-11 15:33:18 发布