1、
var str = "<h1>这是一个标题</h1>"; var parser = new DOMParser(); var doc = parser.parseFromString(str, "text/html"); var html = doc.body.firstChild;
2、
const str = "<h1>这是一个标题</h1>"; const fragment = document.createDocumentFragment(); const range = document.createRange(); range.selectNode(document.body); fragment.appendChild(range.createContextualFragment(str)); const html = fragment.firstChild;
3、
const str = "<h1>这是一个标题</h1>"; const div = document.createElement("div"); div.innerHTML = str; const html = div.firstChild;
标签:const,string,js,html,str,var,div,document From: https://www.cnblogs.com/laremehpe/p/17962020