📜  javascript 从 innerhtml 创建节点 - Javascript 代码示例

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

代码示例2
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;
}