美文网首页
html字符串 转 dom

html字符串 转 dom

作者: 罗不错 | 来源:发表于2020-09-01 09:58 被阅读0次

function createDocumentFragment(txt) {
const template = <div class='child'>${txt}</div>;
let frag = document.createRange().createContextualFragment(template);
return frag;
}

    const container = document.getElementById('container');
    container.appendChild(createDocumentFragment('hello'));

相关文章

网友评论

      本文标题:html字符串 转 dom

      本文链接:https://www.haomeiwen.com/subject/viwmsktx.html