代码如下:
function createElementFromHTML(htmlString) {
var div = document.createElement('div');
div.innerHTML = htmlString.trim();
// Change this to div.childNodes to support multiple top-level nodes.
return div.firstChild;
}
来源:Creating a new DOM element from an HTML string using built-in DOM methods or Prototype