我发现 
<div id="a1">
  <img src="64135.jpg" height="11px" width="12px" border="0"/>
</div>   var _ht=document.getElementById("a1");
 alert(  _ht.innerHTML);
得到字符串img标签它的 />  变成了> 这同我的预期不一样,因为xml中处理标签是需要  <img .. border="0"/> 格式或  <img .. border="0" ></img> 才行,如何处理呢。

解决方案 »

  1.   

    只想到一个笨方法
    遍历element,然后一项一项的添加到空的xml中。
      

  2.   

    alert($('#a1').html().replace(/(<img[^>]*)>/g, '$1\\>')); 
      

  3.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    </head><body>
    <div id="a1">
    <img src="ljlj"  />
    </div>
    <script type="text/javascript">
    alert($('#a1').html().replace(/(<img[^>]*)>/g, '$1 \/>'));  
    </script>
    </body>
    </html>
      

  4.   

    单一的element可以用正则表达式处理,问题是会不会有镶套的情况出现?