利用JS将页面指定部分存为HTML页

<html>
<script language="javascript">
function   saveDoc(id,name)   //id:要保存的数据外层容器ID;name:要保存的文件名字.
      {      
          var   strHTML   =   id.outerHTML;  
          var   winSave   =   window.open();
          var now= new Date();
          var year=now.getYear();
          var month=now.getMonth()+1;
          var day=now.getDate();
          var displayTime=year+'-'+month+'-'+day+name;
          winSave.document.open("text/html","utf-8");  
          winSave.document.write(strHTML);  
          winSave.document.execCommand("SaveAs",true,displayTime+".htm");  
          winSave.close();  
      }
</script>
<body>
<a href="javascript:saveDoc(tableid,'利润表')">保存本表</a>
<table id="tableid">
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>1</td><td>2</td><td>3</td></tr>
</table>
</body>
</html>

你可能感兴趣的:(利用JS将页面指定部分存为HTML页)