Java中jsp页面的打印功能

1、加入javascript代码:

<script language="javascript">


function printScreen(block)
{       
     $("#"+block+" table").attr("border",'1');
     var value = $("#"+block).html();
      var printdetail = window.open("","printDetail","");
     
      printdetail.document.open();
      printdetail.document.write("<HTML><head><link href='<%=basePath%>css/cskt.css' rel='stylesheet' type='text/css' /><style>*^td{color:white};td{font-size:16px;color:black}</style></head><BODY onload='window.print();'>");
      printdetail.document.write("<PRE>");
      printdetail.document.write(value);
      printdetail.document.write("</PRE>");
      printdetail.document.close("</BODY></HTML>");
     
      $("#"+block+" table").attr("border",'0');
}
</script>

2、注意:打印是以一个table表格为区域,而且要用<div></div>把表格套住,并指定<div id="block">:

     <div id = "block">

          <table>

              <tr>

                  <td>

                      打印该表格。

                  </td>

             </tr>

          </table>

3、设置打印按钮:

   <input type="button" name="Button" value="打印" onclick="printScreen('block')"/>

 

注:只能试用与ie浏览器

你可能感兴趣的:(JavaScript,java,jsp,css,IE)