复制两个个html标签之间内容(包括html)

<html>
<head>
<script>

function doIt() 
{
     var x=document.getElementById('dajm');     
     document.form.copyArea.value=x.innerHTML;
     alert(document.form.copyArea.value);
     y = document.form.copyArea.createTextRange();
     y.select();
     y.execCommand("Copy");
}
</script>
</head>

<body onload="doIt()">

<p>Outside Div</p>
<div id="dajm">
  <table border="1" width="100%">
    <tr>
      <td width="50%">Inside Div</td>
      <td width="50%"> </td>
    </tr>
    <tr>
      <td width="50%"> </td>
      <td width="50%"> </td>
    </tr>
  </table>
</div>
<form name="form">
  <input type="hidden" name="copyArea" value>
</form>
<p>Outside Div</p>
</body>
</html>

 去除空行和空格的代码

<html>
<head>
<script>

function doIt() 
{
     var x=document.getElementById('dajm');     
     document.form.copyArea.value=x.innerHTML;
     a = document.form.copyArea.value;
     a = a.replace(/(\ )+/g,"");
     a = a.replace(/<[^<>]+>/g,"");
     a = a.replace(/\n[\s| ]*\r/g,"");
     alert(a);
     y = document.form.copyArea.createTextRange();
     y.select();
     y.execCommand("Copy");
}
</script>
</head>

<body onload="doIt()">

<p>Outside Div</p>
<div id="dajm">
  <table border="1" width="100%">
    <tr>
      <td width="30%">Inside Div</td>
      <td width="40%"> </td>
      <td width="30%"> </td>
    </tr>
    <tr>
    <td width="30%"> </td>
      <td width="40%">123</td>
      <td width="30%">44444</td>
    </tr>
  </table>
</div>
<form name="form">
  <input type="hidden" name="copyArea" value>
</form>
<p>Outside Div</p>
</body>
</html>