📜  js 创建元素 innerhtml - Javascript 代码示例

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

代码示例3
function createElement( str ) {
    var frag = document.createDocumentFragment();

    var elem = document.createElement('div');
    elem.innerHTML = str;

    while (elem.childNodes[0]) {
        frag.appendChild(elem.childNodes[0]);
    }
    return frag;
}