日期:2014-05-16  浏览次数:20465 次

只打印网页上JS指定的区域
<html>
<head>
<script type="text/javascript" language="javascript"> 
function  printPage(){ 
  var newWin=window.open('about:blank', '', ''); 
  var titleHTML=document.getElementById("doctitle").innerHTML; 
  newWin.document.write(titleHTML); 
  newWin.document.location.reload(); 
  newWin.print(); 
}
</script>
</head> 

<body>
表格外的区域是不打印的哦<br>
<br>
<div id="doctitle">
<table cellspacing="0" cellpadding="5" border="1" width="400"><thead><tr><td>序号</td><td>用户组别</td><td>用户姓名</td><td>登录帐号</td>
</tr>
</thead><tbody><tr><td>1</td><td>214</td><td>匡鑫宇</td><td>20111442</td>
</tr>
  <tr><td>2</td><td>214</td><td>祝子豪</td><td>20111441</td>
  </tr>
  <tr><td>3</td><td>214</td><td>周子琪</td><td>20111440</td>
  </tr>
  <tr><td>4</td><td>214</td><td>周立腾</td><td>20111439</td>
  </tr>
  <tr><td>5</td><td>214</td><td>赵启航</td><td>20111438</td>
  </tr>
  <tr><td>6</td><td>214</td><td>招子昊</td><td>20111437</td>
  </tr>
  <tr><td>7</td><td>214</td><td>张政</td><td>20111436</td>
  </tr>
  <tr><td>8</td><td>214</td><td>张权有</td><td>20111435</td>
  </tr>
  <tr><td>9</td><td>214</td><td>曾智茵</td><td>20111434</td>
  </tr>
  <tr><td>10</td><td>214</td><td>曾宇轩</td><td>20111433</td>
  </tr>
</tbody><tfoot></tfoot></table>
</div> <br><br>
<a href= "javascript:;" onclick= "printPage()">只打印表格中的内容 </a> 
</body> 
</html>

?