js Dom转字符串与字符串转Dom

1、dom转字符串

 function parseDom(arg) {

   var objE = document.createElement("div");

   objE.innerHTML = arg;

   return objE.childNodes;

};
 const dom=parseDom(arg)

2、dom转字符串

function nodeToString ( node ) {  
   var tmpNode = document.createElement( "div" );  
   tmpNode.appendChild( node.cloneNode( true ) );  
   var str = tmpNode.innerHTML;  
   tmpNode = node = null; // prevent memory leaks in IE  
   return str;  
}  

var escapedStr = nodeToString( node ).replace( "<" , "<" ).replace( ">" , ">");  
outputNode.innerHTML += escapedStr;

你可能感兴趣的:(工作日记)