js将dom对象转换成字符串

  function nodeToString ( node ) {  
    //createElement()返回一个Element对象
   var tmpNode = document.createElement( "div" ); 
   //appendChild()  参数Node对象   返回Node对象  Element方法
   //cloneNode()  参数布尔类型  返回Node对象   Element方法
   tmpNode.appendChild( node.cloneNode( true ) );  
   var str = tmpNode.innerHTML;  
   tmpNode = node = null; // prevent memory leaks in IE  
   return str;  
  } 

猜你喜欢

转载自blog.csdn.net/zhang070514/article/details/81074807